Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Modestas Filipavicius
generalizable solution for any target word

Modestas Filipavicius

Dec 24, 2025

class Solution: def maxNumberOfBalloons(self, text: str) -> int: target = 'balloon' min_count = 0 # count all chars in text ct = {} for char in text: ct[char] = ct.get(char, 0) + 1 # traverse target word multiple times # until counts dict is depleted while True: for char in target: char_c = ct.get(char, 0) print(f'char: {char}, count: {char_c}') # stop condition if char_c == 0: return min_count # decrement target char count ct[char] = char_c - 1 # whole traversal of target word, increment min_count min_count += 1 return min_count

0

0

Comments
Comments