<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>&quot;balloon&quot;</strong> as possible.</p>

<p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be formed.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/09/05/1536_ex1_upd.JPG" style="width: 132px; height: 35px;" /></strong></p>

<pre>
<strong>Input:</strong> text = &quot;nlaebolko&quot;
<strong>Output:</strong> 1
</pre>

<p><strong class="example">Example 2:</strong></p>

<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/09/05/1536_ex2_upd.JPG" style="width: 267px; height: 35px;" /></strong></p>

<pre>
<strong>Input:</strong> text = &quot;loonbalxballpoon&quot;
<strong>Output:</strong> 2
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> text = &quot;leetcode&quot;
<strong>Output:</strong> 0
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= text.length &lt;= 10<sup>4</sup></code></li>
	<li><code>text</code> consists of lower case English letters only.</li>
</ul>

<p>&nbsp;</p>
<p><strong>Note:</strong> This question is the same as <a href="https://leetcode.com/problems/rearrange-characters-to-make-target-string/description/" target="_blank"> 2287: Rearrange Characters to Make Target String.</a></p>

class Solution {
public:
    int maxNumberOfBalloons(string s) 
    {
        string target = "balloon";

        vector<int>v1(26,0);
        for(int i=0;i<target.length();i++)
        {
            char ch = target[i];
            v1[ch-'a']++;
        }
        vector<int>v2(26,0);
        for(int i=0;i<s.length();i++)  
        {
            char ch = s[i];
            v2[ch-'a']++;
        }
        for(int i=0;i<26;i++)
        {
            if(v1[i]==0)
            {
                continue;
            }
            else
            {
                v2[i] = v2[i] / v1[i];
            }
        }
        int ans=INT_MAX;
        unordered_set<char>st(target.begin(),target.end());
        for(auto ch : st)
        {
            int val = ch - 'a';
            ans=min(ans,v2[val]);
        }
        return ans;
    }
};
8200