Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Home
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
â–²455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets

Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
â–²455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
â–²455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
â–²455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Back to Problems

1189. Maximum Number of Balloons

Easy59.7% Acceptance
Hash TableStringCounting
Asked by:
A
Adobe
ProblemHints (2)Solutions (12)VideosCompanies (1)Notes

Problem Statement

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.

Example 1:

Input: text = "nlaebolko"
Output: 1

Example 2:

Input: text = "loonbalxballpoon"
Output: 2

Example 3:

Input: text = "leetcode"
Output: 0

Constraints:

  • 1 <= text.length <= 104
  • text consists of lower case English letters only.

Note: This question is the same as 2287: Rearrange Characters to Make Target String.

Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
â–²455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions

Approach

In #1189 Maximum Number of Balloons, the goal is to determine how many times the word "balloon" can be formed using the characters of a given string. Since each character can only be used once per formation, the key idea is to analyze the frequency of required characters.

A common approach is to use a hash table or frequency array to count how many times each character appears in the input string. Then compare these counts with the characters needed to form the target word. Some characters appear more than once in "balloon" (such as l and o), so their counts must be handled carefully when determining the limiting factor.

The final answer is determined by identifying the minimum possible formations based on these character frequencies. This approach processes the string once, resulting in O(n) time complexity with O(1) extra space when using a fixed-size character map.

Complexity

ApproachTime ComplexitySpace Complexity
Hash Map / Frequency CountingO(n)O(1)

Video Solution Available

NeetCode

View all video solutions

Problem Hints

Use these hints if you're stuck. Try solving on your own first.

1
Hint 1

Count the frequency of letters in the given string.

2
Hint 2

Find the letter than can make the minimum number of instances of the word "balloon".

Ready to see the solutions?View Solutions

Solutions (12)

Frequency Count Method

This approach involves counting the frequency of each character in the string 'text' and then determining how many full instances of the word 'balloon' can be formed based on these frequencies. We will count the occurrences of the characters 'b', 'a', 'l', 'o', and 'n'. Since 'l' and 'o' appear twice in the word 'balloon', their counts should be halved. Finally, we find the minimum number of complete 'balloon' words that can be formed using these character counts.

Time Complexity: O(n), where n is the length of the input string.
Space Complexity: O(1), since we are using a constant amount of extra space.

CC++JavaPythonC#JavaScript
1#include <stdio.h>
2#include <string.h>
3
4int maxNumberOfBalloons(char* text) {
5    int count[26] =

Explanation

The C solution uses an array of size 26 to store the frequency of each letter in the input string 'text'. The count for 'l' and 'o' is divided by two because they appear twice in 'balloon'. Finally, it calculates the minimum count required among 'b', 'a', 'l', 'o', and 'n' to determine how many instances of 'balloon' can be formed.

Character Frequency Ratio Method

Instead of counting characters explicitly, this approach calculates the maximum number of 'balloon' instances by directly comparing the ratios of character counts required. Specifically, for 'b', 'a', and 'n', the ratio is 1:1, but for 'l' and 'o', the ratio is 1:2 in 'balloon'. This approach simplifies checking character sufficiency by calculating the feasible number of 'balloon' words based on the complete sets of these character combinations.

Time Complexity: O(n), where n is the length of the input string.
Space Complexity: O(1), as it uses a fixed number of variables for counting.

CC++JavaPythonC#JavaScript


Video Solutions

Watch expert explanations and walkthroughs

Maximum Number of Balloons - Leetcode 1189 - Python

NeetCode
7:0325,417 views

Asked By Companies

1 companies
A
Adobe

Prepare for Interviews

Practice problems asked by these companies to ace your technical interviews.

Explore More Problems

Notes

Personal Notes

Jot down your thoughts, approach, and key learnings

0 characters

Similar Problems

Longest Substring Without Repeating CharactersMedium
Integer to RomanMedium
Roman to IntegerEasy
Letter Combinations of a Phone NumberMedium
More similar problems

Related Topics

Hash TableStringCounting

Problem Stats

Acceptance Rate59.7%
DifficultyEasy
Companies1

Practice on LeetCode

Solve with full IDE support and test cases

Solve Now

Frequently Asked Questions

Is Maximum Number of Balloons asked in FAANG interviews?

Yes, variations of string frequency and counting problems are commonly asked in technical interviews at companies like Google, Amazon, and Meta. This problem helps test understanding of hash tables, string manipulation, and counting techniques.

What data structure is best for Maximum Number of Balloons?

A hash table or a frequency array of size 26 works best for this problem. These structures allow efficient counting of characters and constant-time lookups when checking required frequencies.

What is the optimal approach for Maximum Number of Balloons?

The optimal approach is to count the frequency of characters using a hash table or fixed-size array. Then compare these counts with the required letters in the word "balloon". The minimum possible formation based on these counts gives the final result.

Why do we treat 'l' and 'o' differently in Maximum Number of Balloons?

The word "balloon" contains two 'l' characters and two 'o' characters. Because of this, their frequency in the input string must be divided appropriately when calculating how many complete words can be formed.

{
0
}
;
6
for
(
int
i
=
0
;
text
[
i
]
;
i
++
)
7
count
[
text
[
i
]
-
'a'
]
++
;
8
count
[
'l'
-
'a'
]
/=
2
;
9
count
[
'o'
-
'a'
]
/=
2
;
10
int
min
=
count
[
'b'
-
'a'
]
;
11
min
=
min
<
count
[
'a'
-
'a'
]
?
min
:
count
[
'a'
-
'a'
]
;
12
min
=
min
<
count
[
'l'
-
'a'
]
?
min
:
count
[
'l'
-
'a'
]
;
13
min
=
min
<
count
[
'o'
-
'a'
]
?
min
:
count
[
'o'
-
'a'
]
;
14
min
=
min
<
count
[
'n'
-
'a'
]
?
min
:
count
[
'n'
-
'a'
]
;
15
return
min
;
16
}
17
18
int
main
(
)
{
19
char
text
[
]
=
"loonbalxballpoon"
;
20
printf
(
"%d\n"
,
maxNumberOfBalloons
(
text
)
)
;
21
return
0
;
22
}
1
#
include
<stdio.h>
2
#
include
<string.h>
3
4
int
maxNumberOfBalloons
(
char
*
text
)
{
5
int
b
=
0
,
a
=
0
,
l
=
0
,
o
=
0
,
n
=
0
;
6
for
(
int
i
=
0
;
text
[
i
]
;
i
++
)
{
7
if
(
text
[
i
]
==
'b'
)
b
++
;
8
else
if
(
text
[
i
]
==
'a'
)
a
++
;
9
else
if
(
text
[
i
]
==
'l'
)
l
++
;
10
else
if
(
text
[
i
]
==
'o'
)
o
++
;
11
else
if
(
text
[
i
]
==
'n'
)
n
++
;
12
}
13
l
/=
2
;
14
o
/=
2
;
15
return
b
<
a
?
(
b
<
l
?
(
b
<
o
?
(
b
<
n
?
b
:
n
)
:
(
o
<
n
?
o
:
n
)
)
:
(
l
<
o
?
(
l
<
n
?
l
:
n
)
:
(
o
<
n
?
o
:
n
)
)
)
:
16
(
a
<
l
?
(
a
<
o
?
(
a
<
n
?
a
:
n
)
:
(
o
<
n
?
o
:
n
)
)
:
(
l
<
o
?
(
l
<
n
?
l
:
n
)
:
(
o
<
n
?
o
:
n
)
)
)
;
17
}
18
19
int
main
(
)
{
20
char
text
[
]
=
"loonbalxballpoon"
;
21
printf
(
"%d\n"
,
maxNumberOfBalloons
(
text
)
)
;
22
return
0
;
23
}

Explanation

This C solution defines separate counts for each character directly required to form 'balloon'. It then computes how many full 'balloon' sets can be constructed based on these adjusted character counts, particularly halving the 'l' and 'o' counts.