← Back to DSA Animator
Maximum Number of Balloons LC #1189 Easy Frequency Map · Min Bottleneck
Problem

Given a string text, return the maximum number of instances of the word "balloon" that can be formed using letters in text. Each letter can only be used once.

Example 1
Input: text = "nlaebolko"
Output: 1
Example 2
Input: text = "loonbalxballpoon"
Output: 2
Constraints: 1 ≤ text.length ≤ 10⁴ | lowercase English letters only
Try Examples
Custom:
Approach
Count b, a, l, o, n in text — divide l & o by 2
"balloon" needs b×1 a×1 l×2 o×2 n×1. Answer = min of effective counts. The scarcest letter is the bottleneck. O(n) time, O(1) space.
Text Character Strip
b
×1
a
×1
l
×2
o
×2
n
×1
Letter Counters & Bottleneck
b
0
a
0
l
0
raw 0
o
0
raw 0
n
0
min(b,a,l÷2,o÷2,n)
Scan text to count letters
Variables
i
char
b
0
a
0
ans
Step Logic
Press ▶ Play or Next Step to begin.
🎉
Ready
0 / 0
Select an example above and press Play.
Algorithm
1
"balloon" needs: b×1 a×1 l×2 o×2 n×1
2
Count frequency of each required letter in text
3
l and o appear twice in "balloon" → divide counts by 2
4
Return min(freq[b], freq[a], freq[l]/2, freq[o]/2, freq[n])
Time
O(n)
Space
O(1)
Why This Works

Each "balloon" consumes one b, one a, two l's, two o's, and one n. The number you can spell is limited by whichever letter runs out first — the bottleneck. Dividing l and o by 2 converts raw counts into "how many balloons" each letter supports.