DSA problem
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 of the word "balloon" you can form.
Note that the word "balloon" contains the letters b, a, l (twice), o (twice), and n. So forming one "balloon" consumes 1 'b', 1 'a', 2 'l', 2 'o', and 1 'n'. The answer is limited by whichever required letter is in shortest supply, after accounting for letters that are needed multiple times.
Examples
Example 1
Input:
text = "nlaebolko"Output:
1Explanation: The string contains exactly one of each letter needed for "balloon", so we can build the word once.
Example 2
Input:
text = "loonbalxballpoon"Output:
2Explanation: There are enough b, a, l, o, and n characters to spell "balloon" twice. Extra characters like x and p are ignored.
Example 3
Input:
text = "leetcode"Output:
0Explanation: The string is missing several required letters (no b, a, or n), so zero instances can be formed.
Constraints
- 1 <= text.length <= 10^4
- text consists of lowercase English letters only.
3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.