-
Notifications
You must be signed in to change notification settings - Fork 0
/
Balloon Everywhere.cpp
54 lines (45 loc) · 1.08 KB
/
Balloon Everywhere.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//{ Driver Code Starts
//Initial Template for C++
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
//User function Template for C++
class Solution{
public:
int maxInstance(string s){
vector<int>temp1(26,0);
vector<int>temp2(26,0);
string temp="balloon";
for(auto i : temp){
temp1[i-'a']++;
}
int maxi=INT_MIN;
int res=INT_MAX;
for(auto i : s){
temp2[i-'a']++;
}
for(int i=0;i<26;i++){
if(temp1[i]>temp2[i]) return 0;
else if(temp1[i]!=0 && temp2[i]!=0){
int one=temp2[i]/temp1[i];
maxi=max(maxi,one);
res=min(res,one);
}else if(temp1[i]!=0 && temp2[i]==0) return 0;
}
return min(res,maxi);
}
};
//{ Driver Code Starts.
int main(){
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
Solution ob;
cout<<ob.maxInstance(s)<<endl;
}
return 0;
}
// } Driver Code Ends