Maximum Number of Balloons - Problem
Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.
You can use each character in text at most once. Return the maximum number of instances that can be formed.
Input & Output
Example 1 — Basic Case
$
Input:
text = "nlaebolko"
›
Output:
1
💡 Note:
We have: n=1, l=2, a=1, e=1, b=1, o=2, k=1. For 'balloon' we need: b=1, a=1, l=2, o=2, n=1. We can form exactly 1 balloon.
Example 2 — Multiple Balloons
$
Input:
text = "loonbalxballpoon"
›
Output:
2
💡 Note:
We have: l=4, o=4, n=3, b=2, a=2, x=1, p=1. For 'balloon' we need 1b+1a+2l+2o+1n each. We can form 2 balloons: min(2,2,4/2,4/2,3) = 2.
Example 3 — Insufficient Characters
$
Input:
text = "leetcode"
›
Output:
0
💡 Note:
We have: l=1, e=3, t=1, c=1, o=1, d=1. Missing 'b', 'a', 'n' and insufficient 'l', 'o'. Cannot form any balloon.
Constraints
- 1 ≤ text.length ≤ 104
- text consists of lowercase English letters only
Visualization
Tap to expand
Understanding the Visualization
1
Input Analysis
Given string with various characters
2
Character Counting
Count required letters: b, a, l, o, n
3
Calculate Result
Find limiting factor for complete balloons
Key Takeaway
🎯 Key Insight: The answer is determined by the character that appears least frequently relative to how many times it's needed in 'balloon'
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code