[
string
hash table
counter
]
Leetcode 1189 Maximum Number of Balloons
Problem statement
https://leetcode.com/problems/maximum-number-of-balloons/
Solution
All you need to do in this problem is to count number of each symbols, specifically a
, b
, l
, n
, o
. Then we need to find letter with minimum frequency, but also taking into account that we need two l
and two o
.
Complexity
Time complexity is O(n)
, space complexity is O(26)
to keep counter.
Code
class Solution:
def maxNumberOfBalloons(self, text):
cnt = Counter(text)
return min(cnt["b"], cnt["a"], cnt["l"]//2, cnt["o"]//2, cnt["n"])