Maximum number of balloons
November 5, 2022
array-and-hashmapProblem URL: Maximum number of balloons
We will count all the characters, then we will return the minimum of the count of b
, a
, l
, o
, and n
, as the number of l
and o
are counted twice, we will divide the count by 2.
class Solution:
def maxNumberOfBalloons(self, text: str) -> int:
count = collections.Counter(text)
return min([count['b'], count['a'], count['l']//2, count['o']//2, count['n']])
Time Complexity: O(n)
Space Complexity: O(n)