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.

&nbsp;
Example 1:



Input: text = "nlaebolko"
Output: 1


Example 2:



Input: text = "loonbalxballpoon"
Output: 2


Example 3:

Input: text = "leetcode"
Output: 0


&nbsp;
Constraints:


	1 &lt;= text.length &lt;= 104
	text consists of lower case English letters only.


class Solution:
    def maxNumberOfBalloons(self, text: str) -> int:
        freq = {'b': 0, 'a': 0, 'l': 0, 'o': 0, 'n': 0}
        
        for char in text:
            if not char in freq:
                continue
                
            step = 0.5 if char == 'l' or char == 'o' else 1
            
            freq[char] += step
        
        result = min(freq.values())
        
        return floor(result)
class Solution {

    public int maxNumberOfBalloons(String text) {
        return maxNumberOfWords(text, "balloon");
    }

    private int maxNumberOfWords(String text, String word) {
        final int[] tFrequencies = new int[26];
        for (int i = 0; i < text.length(); ++i) {
            tFrequencies[text.charAt(i) - 'a']++;
        }
        final int[] wFrequencies = new int[26];
        for (int i = 0; i < word.length(); ++i) {
            wFrequencies[word.charAt(i) - 'a']++;
        }
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < 26; ++i) {
            if (wFrequencies[i] > 0) {
                final int count = (tFrequencies[i] / wFrequencies[i]);
                if (count < min) {
                    min = count;
                }
            }
        }
        return min;
    }

}
class Solution {
public:
    int maxNumberOfBalloons(string text) {
        map<char,int>m;
        for(int i=0;i<text.length();i++)
        {
            m[text[i]]++;
        }
        string s="balloon";
        int flag=1;
        int c=0;
        while(1)
        {
            for(int i=0;i<s.length();i++)
            {
                m[s[i]]--;
                if(m[s[i]]==-1)
                {
                    flag=0;
                }
            }
            if(flag==0)
                break;
            c++;
        }
        return c;
    }
};
/**
 * @param {string} text
 * @return {number}
 */
var maxNumberOfBalloons = function(text) {
//    1. create hashmap with "balloon" letters
//    2. keep track of how many letters in text belong to "balloon"
//     3. account for fact that we need two "l" and "o" per "balloon" instance
//    4. then select all map values and get the minimum - this will be the max value
    
    const balloonMap = {
        "b": 0,
        "a": 0,
        "l": 0,
        "o": 0,
        "n": 0
    }
    
    for (const char of text) {
        if (balloonMap[char] !== undefined) {
            balloonMap[char] += 1
        }
    }
    
    const letterFreq = []
    for (const key in balloonMap) {
        if (["l", "o"].includes(key)) {
            letterFreq.push(Math.floor(balloonMap[key]/2))
        } else {
            letterFreq.push(balloonMap[key])
        }
    }
    return Math.min(...letterFreq)
};
Maximum Number of Balloons