website/content.en/ChapterFour/1100~1199/1189.Maximum-Number-of-Balloons.md
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 <= 10^4text consists of lower case English letters only.Given a string text, you need to use the letters in text to form as many instances of the word "balloon" as possible. Each letter in the string text can be used at most once. Return the maximum number of instances of the word "balloon" that can be formed.
Note:
package leetcode
func maxNumberOfBalloons(text string) int {
fre := make([]int, 26)
for _, t := range text {
fre[t-'a']++
}
// The frequency of character b is the element value corresponding to array index 1
// The frequency of character a is the element value corresponding to array index 0
// The frequency of character l is the element value corresponding to array index 11; there are 2 l's here, so the element value needs to be divided by 2
// The frequency of character o is the element value corresponding to array index 14; there are 2 o's here, so the element value needs to be divided by 2
// The frequency of character n is the element value corresponding to array index 13
return min(fre[1], min(fre[0], min(fre[11]/2, min(fre[14]/2, fre[13]))))
}