Skip to content
LC-1189 Easy LeetCode

1189. Maximum Number of Balloons

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 60% Topics: Hash Table, String, Counting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

import collections


class Solution(object):
    def maxNumberOfBalloons(self, text):
        """
        :type text: str
        :rtype: int
        """
        TARGET = "balloon"
        source_count = collections.Counter(text)
        target_count = collections.Counter(TARGET)
        return min(source_count[c]//target_count[c] for c in target_count.iterkeys())

Solution from kamyu104/LeetCode-Solutions · MIT