Question
Given a string
text
, you want to use the characters oftext
to form as many instances of the word “balloon” as possible.You can use each character in
text
at most once. Return the maximum number of instances that can be formed.
This is atesla question
class Solution:
def maxNumberOfBalloons(self, text: str) -> int:
textMap = Counter(text)
balloonMap = Counter("balloon")
res = len(text)
for c in balloonMap:
res = min(res, textMap[c] // balloonMap[c])
return res