Leetcode 1297 Solution

This article provides solution to leetcode question 1297 (maximum-number-of-balloons)

https://leetcode.com/problems/maximum-number-of-balloons

Solution

class Solution:
    def maxNumberOfBalloons(self, text: str) -> int:
        m = collections.defaultdict(int)

        for ch in text:
            m[ch] += 1

        cnt = 10000
        cnt = min(cnt, m["b"])
        cnt = min(cnt, m["a"])
        cnt = min(cnt, m["l"] // 2)
        cnt = min(cnt, m["o"] // 2)
        cnt = min(cnt, m["n"])

        return cnt