Imagine you're organizing a birthday party and want to spell out the word "balloon" using alphabet magnets. You have a collection of letter magnets represented by a string text, where each character can only be used once.
Your goal is to determine the maximum number of complete instances of the word "balloon" you can form using the available letters.
Example: If you have the letters "nlaebolko", you can form exactly 1 instance of "balloon" because you have all the required letters: b(1), a(1), l(2), o(2), n(1).
Note: The word "balloon" requires: 1 'b', 1 'a', 2 'l's, 2 'o's, and 1 'n'.
Input & Output
Visualization
Time & Space Complexity
Single pass through the string to count characters, plus constant time to calculate result
Only need to store counts for 5 specific characters (b,a,l,o,n), regardless of input size
Constraints
- 1 โค text.length โค 104
- text consists of lowercase English letters only
- Each character in text can be used at most once