Grokking Microsoft Coding Interview
0% completed
Maximum Number of Balloons (easy)
A
Anonymous
· 2 years ago
c = Counter(text) min_count = min([c.get('b', 0), c.get('a', 0), c.get('l', 0) // 2, c.get('o', 0) // 2, c.get('n', 0)]) return min_count
A
Anonymous
· 2 years ago
from collections import Counter class Solution: def maxNumberOfBalloons(self, text: str) -> int: min_count = float('inf') balloon_counter = Counter('balloon') text_counter = Counter(text) for char, freq in balloon_counter.items(): if char not in text_counter: return 0 else: min_count = min(min_count, text_counter[char] // freq) return min_count
Reading Progress
0%