Maximum Number of Balloons (Leetcode 1189)
Problem Link: https://leetcode.com/problems/maximum-number-of-balloons/description/
class Solution:
def maxNumberOfBalloons(self, text: str) -> int:
inputDict={}
balloonDict={}
for ch in text:
inputDict[ch]=inputDict.get(ch,0)+1
for ch in 'balloon':
balloonDict[ch]=balloonDict.get(ch,0)+1
res=float('inf')
print(inputDict, balloonDict)
for ch in 'balloon':
if(ch not in inputDict):
return 0
res=min(res,inputDict[ch]//balloonDict[ch])
return res
Last updated