1189. Maximum Number of Balloons LeetCode Solution
In this guide, you will get 1189. Maximum Number of Balloons LeetCode Solution with the best time and space complexity. The solution to Maximum Number of Balloons problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Maximum Number of Balloons solution in C++
- Maximum Number of Balloons solution in Java
- Maximum Number of Balloons solution in Python
- Additional Resources

Problem Statement of Maximum Number of Balloons
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.
Complexity Analysis
- Time Complexity:
- Space Complexity:
1189. Maximum Number of Balloons LeetCode Solution in C++
class Solution {
public:
int maxNumberOfBalloons(string text) {
int ans = INT_MAX;
vector<int> count(26);
for (char c : text)
++count[c - 'a'];
for (char c : string("ban"))
ans = min(ans, count[c - 'a']);
for (char c : string("lo"))
ans = min(ans, count[c - 'a'] / 2);
return ans;
}
};
/* code provided by PROGIEZ */
1189. Maximum Number of Balloons LeetCode Solution in Java
class Solution {
public int maxNumberOfBalloons(String text) {
int ans = Integer.MAX_VALUE;
int[] count = new int[26];
for (char c : text.toCharArray())
++count[c - 'a'];
for (char c : new char[] {'b', 'a', 'n'})
ans = Math.min(ans, count[c - 'a']);
for (char c : new char[] {'o', 'l'})
ans = Math.min(ans, count[c - 'a'] / 2);
return ans;
}
}
// code provided by PROGIEZ
1189. Maximum Number of Balloons LeetCode Solution in Python
class Solution:
def maxNumberOfBalloons(self, text: str) -> int:
count = collections.Counter(text)
return min(
count['b'],
count['a'],
count['l'] // 2, count['o'] // 2, count['n'])
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.