LeetCode //C - 1189. Maximum Number of Balloons
1189. Maximum Number of BalloonsGiven 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:1Example 2:Input:text “loonbalxballpoon”Output:2Example 3:Input:text “leetcode”Output:0Constraints:1 t e x t . l e n g t h 10 4 1 text.length 10^41text.length104text consists of lower case English letters only.From: LeetCodeLink: 1189. Maximum Number of BalloonsSolution:Ideas:count letters, then take the minimum of b, a, l/2, o/2, and n.Code:intmaxNumberOfBalloons(char*text){intcount[26]{0};for(inti0;text[i]!\0;i){count[text[i]-a];}intbcount[b-a];intacount[a-a];intlcount[l-a]/2;intocount[o-a]/2;intncount[n-a];intansb;if(aans)ansa;if(lans)ansl;if(oans)anso;if(nans)ansn;returnans;}