605. Maximum Number of Balloons
You are given a string text of lowercase English letters. You want to spell the word "balloon" as many times as possible using the letters of text, where each character of text can be used at most once.
Return the maximum number of complete copies of "balloon" you can form. If even one copy is impossible, return 0.
Note that "balloon" needs two ls and two os per copy — that detail is where most wrong answers come from.
Example 1:
Input: text = "nlaebolko"
Output: 1
Explanation: The letters b, a, l, l, o, o, n can each be found once in the text, which is exactly one copy of "balloon". There is no second l or o, so a second copy is impossible.
Example 2:
Input: text = "loonbalxballpoon"
Output: 2
Explanation: The text contains 2 b's, 2 a's, 4 l's, 4 o's, and 2 n's — enough for exactly two copies of "balloon".
Example 3:
Input: text = "leetcode"
Output: 0
Explanation: There is no b (and no a) anywhere in the text, so not even one copy can be spelled.
Constraints:
- 1 ≤ text.length ≤ 10⁴
- text consists of lowercase English letters only
Hints:
You never need to consider positions or order — only how many of each letter the text contains. Count the letters first.
One copy of "balloon" consumes 1 b, 1 a, 2 l, 2 o, 1 n. How many copies does your stock of l's alone allow? Your stock of o's?
The answer is the minimum over the needed letters of count(letter) / need(letter), using integer division: min(b, a, l/2, o/2, n).
▶ Run checks these sample cases. Submit also runs hidden edge cases.
Input: text = "nlaebolko"
Expected output: 1