Bob is very fond of balloons. Once he visited an amusement park with his mother. The mother told Bob that she would buy him a balloon only if he answer her problem right. She gave Bob a string S [contains only lowercase characters] and asked him to use the characters of string to form as many instances of the word "balloon" as possible. Return the maximum number of instances that can be formed.
Help Bob to solve the problem.
Note: You can use each character in the string at most once. 
Example 1:
Input:
S: nlaebolko
Output: 1
Explanation:
Here, the number of occurence of 'b' = 1
of occurence of 'a' = 1
of occurence of 'l' = 2
of occurence of 'o' = 2
of occurence of 'n' = 1
So, we can form 1 "balloon" using the letters.
 
Example 2: 
Input:
S: loonbalxballpoon
Output: 2
Explanation:
Here, the number of occurence of 'b' = 2
of occurence of 'a' = 2
of occurence of 'l' = 4
of occurence of 'o' = 4
of occurence of 'n' = 2
So, we can form 2 "balloon" using the letters.
 
Your Task:
The task is to complete the function maxInstance() which takes a string as the only input parameter and should return the maximum instances that can be formed of the word "balloon" using the given string.
Expected Time Complexity: O(n), n is size of the given string.
Expected Auxiliary Space: O(26).
Constraints:
1 <= s.length <= 10^{6}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: class Solution:

    def maxInstance(self, s : str) -> int:

        # code here

Solutions:
from collections import Counter

class Solution:

	def maxInstance(self, s: str) -> int:
		x = Counter(s)
		if x['a'] == 0 or x['b'] == 0 or x['l'] == 0 or (x['o'] == 0) or (x['n'] == 0):
			return 0
		if x['a'] == x['n'] and x['n'] == x['b'] and (x['l'] == 2 * x['a']) and (x['l'] == x['o']):
			return x['a']
		else:
			k = min(x['a'], x['b'], x['n'])
			j = min(x['l'], x['o'])
			if j == 0 or k == 0:
				return 0
			else:
				for i in range(k, 0, -1):
					if j // i >= 2:
						return i
		return 0


class Solution:

	def maxInstance(self, s: str) -> int:
		dic = {}
		dic['b'] = 0
		dic['a'] = 0
		dic['l'] = 0
		dic['o'] = 0
		dic['n'] = 0
		for i in s:
			if i in dic:
				dic[i] += 1
		f1 = 0
		f2 = 0
		if dic['o'] >= 2:
			dic['o'] = dic['o'] // 2
		else:
			return 0
		if dic['l'] >= 2:
			dic['l'] = dic['l'] // 2
		else:
			return 0
		f1 = min(dic['l'], dic['o'])
		f2 = min(dic['b'], dic['a'], dic['n'])
		return min(f1, f2)


class Solution:

	def maxInstance(self, s: str) -> int:
		B = s.count('b')
		A = s.count('a')
		L = s.count('l') // 2
		O = s.count('o') // 2
		N = s.count('n')
		return min(B, A, L, O, N)


class Solution:

	def maxInstance(self, s: str) -> int:
		letters = {'b': 0, 'a': 0, 'l': 0, 'o': 0, 'n': 0}
		for i in s:
			if i in letters.keys():
				letters[i] += 1
		for l in 'lo':
			letters[l] = letters[l] // 2
		return min(letters.values())


class Solution:

	def maxInstance(self, s: str) -> int:
		b = s.count('b')
		a = s.count('a')
		l = s.count('l')
		o = s.count('o')
		n = s.count('n')
		if min(b, a, n) < min(l, o) // 2:
			return min(b, a, n)
		else:
			return min(l, o) // 2


import math

class Solution:

	def maxInstance(self, s: str) -> int:
		mini = math.inf
		s1 = 'balloon'
		dicti = {}
		for i in s:
			if i not in dicti and i in s1:
				dicti[i] = 1
			elif i in dicti:
				dicti[i] += 1
		if len(dicti) < 5:
			return 0
		for i in dicti:
			if i == 'l' or i == 'o':
				mini = min(mini, dicti[i] // 2)
			else:
				mini = min(mini, dicti[i])
		if mini == math.inf:
			return 0
		return mini


class Solution:

	def maxInstance(self, s: str) -> int:
		my_dict = dict()
		for ch in s:
			if ch in my_dict:
				my_dict[ch] += 1
			else:
				my_dict[ch] = 1
		answer = 0
		duration = True
		answer = min(my_dict['b'], my_dict['a'], my_dict['l'] // 2, my_dict['o'] // 2, my_dict['n'])
		return answer


class Solution:

	def maxInstance(self, s: str) -> int:
		my_dict = dict()
		for ch in s:
			if ch in my_dict:
				my_dict[ch] += 1
			else:
				my_dict[ch] = 1
		answer = 0
		duration = True
		while duration:
			for char in 'balloon':
				if char in my_dict:
					if my_dict[char] <= 0:
						duration = False
						break
					my_dict[char] -= 1
				else:
					duration = False
					break
			if duration:
				answer += 1
		return answer


class Solution:

	def maxInstance(self, s: str) -> int:
		hmap = {}
		for i in range(len(s)):
			if s[i] == 'b' or s[i] == 'a' or s[i] == 'l' or (s[i] == 'o') or (s[i] == 'n'):
				if s[i] in hmap:
					hmap[s[i]] += 1
				else:
					hmap[s[i]] = 1
		hmap['o'] = hmap['o'] // 2
		hmap['l'] = hmap['l'] // 2
		ans = len(s)
		for item in hmap:
			count = hmap[item]
			ans = min(count, ans)
		return ans


class Solution:

	def maxInstance(self, s: str) -> int:
		(b, a, l, o, n) = (0, 0, 0, 0, 0)
		for i in range(len(s)):
			if 'b' == s[i]:
				b += 1
			if 'a' == s[i]:
				a += 1
			if 'l' == s[i]:
				l += 1
			if 'o' == s[i]:
				o += 1
			if 'n' == s[i]:
				n += 1
		return min(b, a, l // 2, o // 2, n)


class Solution:

	def maxInstance(self, s: str) -> int:
		a = []
		(c, d, e, f, g) = (0, 0, 0, 0, 0)
		for i in range(len(s)):
			if s[i] == 'b':
				c += 1
			elif s[i] == 'a':
				d += 1
			elif s[i] == 'l':
				e += 1
			elif s[i] == 'o':
				f += 1
			elif s[i] == 'n':
				g += 1
		k = min(c, d, e // 2, f // 2, g)
		if k > 0:
			return k
		else:
			return 0


from collections import Counter

class Solution:

	def maxInstance(self, s: str) -> int:
		store = Counter(s)
		output = min(store['a'], store['b'], store['n'])
		output = min(output, store['l'] // 2)
		output = min(output, store['o'] // 2)
		return output


class Solution:

	def maxInstance(self, s: str) -> int:
		k = 'balloon'
		hm = {}
		for a in k:
			hm[a] = s.count(a)
		hm['o'] = int(hm['o'] / 2)
		hm['l'] = int(hm['l'] / 2)
		return min(hm.values())


class Solution:

	def maxInstance(self, s: str) -> int:
		counter = {}
		balloon_count = {'b': 1, 'a': 1, 'l': 2, 'o': 2, 'n': 1}
		for c in s:
			if c in balloon_count:
				if c in counter:
					counter[c] += 1
				else:
					counter[c] = 1
		ans = float('inf')
		for (letter, count) in counter.items():
			ans = min(ans, count // balloon_count[letter])
		return ans


class Solution:

	def maxInstance(self, s: str) -> int:
		dic = {}
		s1 = 'balloon'
		for i in s1:
			if i in dic:
				dic[i] += 1
			else:
				dic[i] = 1
			if i not in s:
				return 0
		dics = {}
		for i in s:
			if i in dics:
				dics[i] += 1
			else:
				dics[i] = 1
		c = 0
		while True:
			if dic['b'] <= dics['b'] and dic['a'] <= dics['a'] and (dic['l'] <= dics['l']) and (dic['o'] <= dics['o']) and (dic['n'] <= dics['n']):
				dics['b'] -= dic['b']
				dics['a'] -= dic['a']
				dics['l'] -= dic['l']
				dics['o'] -= dic['o']
				dics['n'] -= dic['n']
			else:
				return c
			c += 1


class Solution:

	def maxInstance(self, s: str) -> int:
		d = {}
		s1 = 'balloon'
		c = ''
		l = []
		for i in s:
			if i in s1:
				c += i
		for i in c:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		for (i, j) in d.items():
			if j == 0:
				return 0
				break
			elif i == 'l' or i == 'o':
				l.append(j // 2)
			else:
				l.append(j)
		return min(l)


class Solution:

	def maxInstance(self, s):
		b = s.count('b')
		a = s.count('a')
		l = s.count('l')
		o = s.count('o')
		n = s.count('n')
		if b == 0 or a == 0 or l == 0 or (o == 0) or (n == 0):
			return 0
		else:
			minSingleChar = min(b, min(a, n))
			minDoubleChar = min(l, o)
			minDoubleChar //= 2
			return min(minSingleChar, minDoubleChar)


class Solution:

	def maxInstance(self, s: str) -> int:
		max_ = 900000
		alpha = [0] * 26
		for i in s:
			if i in 'balloon':
				alpha[ord(i) - ord('a')] += 1
		if alpha[ord('a') - ord('a')] < max_:
			max_ = alpha[ord('a') - ord('a')]
		if alpha[ord('b') - ord('a')] < max_:
			max_ = alpha[ord('b') - ord('a')]
		if alpha[ord('l') - ord('a')] // 2 < max_:
			max_ = alpha[ord('l') - ord('a')] // 2
		if alpha[ord('n') - ord('a')] < max_:
			max_ = alpha[ord('n') - ord('a')]
		if alpha[ord('o') - ord('a')] // 2 < max_:
			max_ = alpha[ord('o') - ord('a')] // 2
		return max_


from collections import Counter

class Solution:

	def maxInstance(self, s: str) -> int:
		counter = Counter(s)
		return min(counter.get('b', 0), counter.get('a', 0), counter.get('l', 0) // 2, counter.get('o', 0) // 2, counter.get('n', 0))


class Solution:

	def maxInstance(self, s: str) -> int:
		d = {}
		for i in s:
			if i not in d and i in 'balon':
				d[i] = 1
			elif i == 'a' or i == 'b' or i == 'l' or (i == 'o') or (i == 'n'):
				d[i] += 1
		ans = 999999
		for i in 'balon':
			if i in d and i in 'ban':
				ans = min(ans, d[i])
			else:
				ans = min(ans, d[i] // 2)
		return ans


class Solution:

	def maxInstance(self, s: str) -> int:
		dic = {'b': 0, 'a': 0, 'l': 0, 'o': 0, 'n': 0}
		for i in s:
			if i in dic:
				dic[i] += 1
		lst = []
		for (i, j) in dic.items():
			if i == 'l' or i == 'o':
				lst += [j // 2]
			else:
				lst += [j]
		return min(lst)


class Solution:

	def maxInstance(self, s: str) -> int:
		B = 'balon'
		d = {}
		for i in s:
			if i in B:
				if i in d:
					d[i] += 1
				else:
					d[i] = 1
		d['l'] = d.get('l') // 2
		d['o'] = d.get('o') // 2
		return min(d.values())


class Solution:

	def maxInstance(self, s: str) -> int:
		d = dict()
		for ele in 'balloon':
			d[ele] = 0
		for ele in s:
			if ele in d.keys():
				d[ele] = d[ele] + 1
		z = []
		for ele in d.keys():
			if ele != 'l' and ele != 'o':
				z.append(d[ele])
			else:
				z.append(d[ele] // 2)
		return int(min(z))


class Solution:

	def maxInstance(self, s: str) -> int:
		S = s
		a = S.count('b')
		b = S.count('a')
		c = S.count('l') // 2
		d = S.count('o') // 2
		e = S.count('n')
		return min(a, b, c, d, e)


class Solution:

	def maxInstance(self, s: str) -> int:
		i = 0
		j = 0
		k = -1
		l = 0
		d = {}
		for i in s:
			if i not in d:
				d[i] = 1
			else:
				d[i] = d[i] + 1
		if 'l' in d:
			d['l'] = int(d['l'] / 2)
		if 'o' in d:
			d['o'] = int(d['o'] / 2)
		p = ['b', 'l', 'a', 'o', 'n']
		for i in p:
			if i not in d:
				break
			elif k == -1:
				k = d[i]
			else:
				k = min(k, d[i])
		return k


from collections import Counter

class Solution:

	def maxInstance(self, s: str) -> int:
		c = Counter(s)
		d = {'b': 1, 'a': 1, 'l': 2, 'o': 2, 'n': 1}
		ans = 1000000000.0
		for i in c:
			if i in 'balon':
				ans = min(ans, c[i] // d[i])
		return ans


class Solution:

	def maxInstance(self, s: str) -> int:
		lst = [0] * 26
		for i in range(len(s)):
			lst[ord(s[i]) - ord('a')] += 1
		c = 2 ** 31
		lst2 = [0] * 26
		lst2[0] = 1
		lst2[1] = 1
		lst2[11] = 2
		lst2[13] = 1
		lst2[14] = 2
		for i in range(len(s)):
			if i == 0 or i == 1 or i == 11 or (i == 13) or (i == 14):
				c = min(c, lst[i] // lst2[i])
		return c


class Solution:

	def maxInstance(self, s: str) -> int:
		b = s.count('b')
		a = s.count('a')
		l = s.count('l')
		o = s.count('o')
		n = s.count('n')
		t = min(b, a, l, o, n)
		if t == 0 or (b == 0 or a == 0 or n == 0 or (l <= 1) or (o <= 1)):
			return 0
		else:
			for i in range(1, t + 1):
				b = b - 1
				a = a - 1
				l = l - 2
				o = o - 2
				n = n - 1
				if b == 0 or a == 0 or n == 0 or (l <= 1) or (o <= 1):
					break
		return i


class Solution:

	def maxInstance(self, s: str) -> int:
		d = {'b': 0, 'a': 0, 'l': 0, 'o': 0, 'n': 0}
		for i in range(len(s)):
			if s[i] == 'b':
				d['b'] += 1
			elif s[i] == 'a':
				d['a'] += 1
			elif s[i] == 'l':
				d['l'] += 1
			elif s[i] == 'o':
				d['o'] += 1
			elif s[i] == 'n':
				d['n'] += 1
		for j in d:
			if j == 'l':
				d[j] = d[j] // 2
			elif j == 'o':
				d[j] = d[j] // 2
		u = []
		for j in d:
			u.append(d[j])
		return min(u)


class Solution:

	def maxInstance(self, s: str) -> int:
		di = dict()
		for i in 'balloon':
			di[i] = int()
		for i in s:
			if i in 'balloon':
				di[i] += 1
		Min = int(1000000000.0)
		di['l'] //= 2
		di['o'] //= 2
		for i in di:
			Min = min(Min, di[i])
		return Min if Min != int(1000000000.0) else 0


from collections import Counter
import math

class Solution:

	def maxInstance(self, s: str) -> int:
		dict1 = Counter(s)
		minimum = math.inf
		dict2 = Counter('balloon')
		for i in dict2:
			if i in dict1:
				minimum = min(minimum, dict1[i] // dict2[i])
		return minimum


class Solution:

	def maxInstance(self, s: str) -> int:
		a = []
		stg = 'balloon'
		for i in s:
			if i in stg:
				a.append(i)
		bc = a.count('b')
		ac = a.count('a')
		lc = a.count('l') // 2
		oc = a.count('o') // 2
		nc = a.count('n')
		m = min(ac, bc, nc)
		if 'b' in a and 'a' in a and ('l' in a) and ('o' in a) and ('n' in a):
			return min(ac, bc, nc, lc, oc)
		else:
			return '0'


class Solution:

	def maxInstance(self, S):
		count = [0] * 26
		for c in S:
			count[ord(c) - ord('a')] += 1
		return min(count[1], count[0], count[11] // 2, count[14] // 2, count[13])


class Solution:

	def maxInstance(self, s: str) -> int:
		dict1 = {}
		l1 = ['b', 'a', 'l', 'l', 'o', 'o', 'n']
		for i in range(len(s)):
			if s[i] in l1 and s[i] in dict1:
				dict1[s[i]] += 1
			elif s[i] in l1 and s[i] not in dict1:
				dict1[s[i]] = 1
		x1 = dict1['b']
		x2 = dict1['a']
		x3 = dict1['l']
		x4 = dict1['o']
		x5 = dict1['n']
		x3 //= 2
		x4 //= 2
		min1 = min(x1, x2)
		min2 = min(min1, x3)
		min3 = min(min2, x4)
		min4 = min(min3, x5)
		return min4


class Solution:

	def maxInstance(self, s):
		t = []
		w = 'balloon'
		for i in w:
			if i == 'l' or i == 'o':
				e = s.count(i)
				r = e // 2
				t.append(r)
				t.append(e - r)
			else:
				t.append(s.count(i))
		return min(t)


class Solution:

	def maxInstance(self, s: str) -> int:
		a = [0] * 5
		for i in s:
			if i == 'b':
				a[0] += 1
			elif i == 'a':
				a[1] += 1
			elif i == 'l':
				a[2] += 1
			elif i == 'o':
				a[3] += 1
			elif i == 'n':
				a[4] += 1
		a[2] = a[2] // 2
		a[3] = a[3] // 2
		return min(a)


class Solution:

	def maxInstance(self, s: str) -> int:
		l = []
		c = 0
		d = 0
		se = list(set(s))
		for i in se:
			if i == 'b':
				l.append(s.count(i))
			elif i == 'o':
				c = s.count(i)
				l.append(s.count(i))
			elif i == 'l':
				d = s.count(i)
			elif i == 'n':
				l.append(s.count(i))
		l.append(c // 2)
		l.append(d // 2)
		return min(l)


import math

class Solution:

	def maxInstance(self, s: str) -> int:
		d = {}
		min = 0
		for i in range(26):
			d[chr(97 + i)] = 0
		for i in s:
			d[i] = d[i] + 1
		if min < d['b']:
			min = d['b']
		if min > d['a']:
			min = d['a']
		if min > d['l'] // 2:
			min = d['l'] // 2
		if min > d['o'] // 2:
			min = d['o'] // 2
		if min > d['n']:
			min = d['n']
		return min


import math

class Solution:

	def maxInstance(self, s: str) -> int:
		d = {}
		for i in s:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		k = min({d['b'], d['a'], d['l'] / 2, d['o'] / 2, d['n']})
		return math.floor(k)


class Solution:

	def maxInstance(self, s: str) -> int:
		bal = dict()
		k = ['b', 'a', 'l', 'o', 'n']
		bal['b'] = 0
		bal['a'] = 0
		bal['l'] = 0
		bal['o'] = 0
		bal['n'] = 0
		for i in s:
			if i in k:
				bal[i] += 1
		bal['l'] = bal['l'] // 2
		bal['o'] = bal['o'] // 2
		return min(bal.values())


class Solution:

	def maxInstance(self, s: str) -> bool:
		diction = {'b': 0, 'a': 0, 'l': 0, 'o': 0, 'n': 0}
		for i in s:
			if i in diction:
				diction[i] += 1
		diction['l'] //= 2
		diction['o'] //= 2
		return min(diction.values())


import sys
from collections import defaultdict

class Solution:

	def maxInstance(self, s: str) -> int:
		hmap = defaultdict(int)
		for i in range(0, len(s)):
			if s[i] not in hmap:
				hmap[s[i]] = 1
			else:
				hmap[s[i]] += 1
		newstr = 'balon'
		for i in range(0, len(newstr)):
			if newstr[i] == 'l' or newstr[i] == 'o':
				hmap[newstr[i]] = hmap[newstr[i]] // 2
		mini = sys.maxsize
		for i in range(0, len(newstr)):
			mini = min(mini, hmap[newstr[i]])
		return mini


class Solution:

	def maxInstance(self, s: str) -> int:
		temp = [0, 0, 0, 0, 0]
		for i in s:
			if i == 'b':
				temp[0] += 1
			elif i == 'a':
				temp[1] += 1
			elif i == 'l':
				temp[2] += 1
			elif i == 'o':
				temp[3] += 1
			elif i == 'n':
				temp[4] += 1
			else:
				continue
		temp1 = min(temp[0], temp[1], temp[4])
		temp2 = int(min(temp[2], temp[3]) / 2)
		result = min(temp1, temp2)
		return result


class Solution:

	def maxInstance(self, s: str) -> int:
		d = {'b': 0, 'a': 0, 'l': 0, 'o': 0, 'n': 0}
		for i in s:
			if i in d:
				d[i] += 1
		if d['b'] >= 1 and d['a'] >= 1 and (d['n'] >= 1) and (d['l'] >= 2) and (d['o'] >= 2):
			c = min(d['b'], d['a'], d['n'])
			k = min(d['l'] // 2, d['o'] // 2)
			if c == k:
				return c
			return min(c, k)
		return 0


import math

class Solution:

	def maxInstance(self, s: str) -> int:
		d = {}
		str1 = 'balloon'
		for i in s:
			if i not in d and i in str1:
				d[i] = 1
			elif i in str1 and i in d:
				d[i] += 1
		return min(min(d.values()), math.floor(min(d['l'], d['o']) // 2))


class Solution:

	def maxInstance(self, s: str) -> int:
		ballon_map = {'b': 1, 'a': 1, 'l': 2, 'o': 2, 'n': 1}
		string_map = {}
		for c in s:
			if not string_map.get(c):
				string_map[c] = 1
			else:
				string_map[c] += 1
		count = 0
		fin = False
		while True:
			for (k, v) in ballon_map.items():
				val = string_map.get(k)
				if val:
					newval = val - v
					if newval < 0:
						fin = True
						break
					else:
						string_map[k] = newval
				else:
					fin = True
					break
			if fin:
				break
			count += 1
		return count


from collections import Counter

class Solution:

	def maxInstance(self, s: str) -> int:
		c1 = Counter(s)
		c2 = Counter('balloon')
		s = []
		for i in c1:
			if i == 'b':
				s.append(c1[i] // 1)
			elif i == 'a':
				s.append(c1[i] // 1)
			elif i == 'l':
				s.append(c1[i] // 2)
			elif i == 'o':
				s.append(c1[i] // 2)
			elif i == 'n':
				s.append(c1[i] // 1)
		return min(s)


class Solution:

	def maxInstance(self, s: str) -> int:
		string = 'balloon'
		dictionary = {}
		for i in string:
			dictionary[i] = s.count(i)
		dictionary['o'] = int(dictionary['o']) // 2
		dictionary['l'] = int(dictionary['l']) // 2
		return min(dictionary.values())


class Solution:

	def maxInstance(self, s: str) -> int:
		count_dict = dict()
		b_dict = {'b': 1, 'a': 1, 'l': 2, 'o': 2, 'n': 1}
		multiplier = []
		for letter in s:
			count_dict[letter] = count_dict.get(letter, 0) + 1
		for key in b_dict:
			if key in count_dict:
				multiplier.append(count_dict[key] // b_dict[key])
		if len(multiplier) == 5:
			return min(multiplier)
		else:
			return 0


import sys

class Solution:

	def maxInstance(self, s: str) -> int:
		letters = {'b': 1, 'a': 1, 'l': 2, 'o': 2, 'n': 1}
		count = sys.maxsize
		freqs = dict()
		for c in s:
			freqs[c] = freqs.get(c, 0) + 1
		for (letter, freq) in letters.items():
			count = min(count, freqs.get(letter, 0) // freq)
		return count


class Solution:

	def maxInstance(self, s: str) -> int:
		d = [0 for i in range(26)]
		for i in s:
			x = ord(i) - 97
			d[x] += 1
		a = 0
		b = 1
		l = 11
		o = 14
		n = 13
		return min(d[0], d[1], int(d[11] / 2), int(d[14] / 2), d[13])


class Solution:

	def maxInstance(self, s: str) -> int:
		myList = dict()
		for ch in 'balon':
			myList[ch] = 0
		for ch in s:
			if ch in 'balon':
				myList[ch] += 1
		myList['o'] = myList['o'] // 2
		myList['l'] = myList['l'] // 2
		return min(myList.values())


class Solution:

	def maxInstance(self, s: str) -> int:
		ans = 10 ** 6
		d = {}
		for i in s:
			d[i] = d.get(i, 0) + 1
		for i in ('b', 'a', 'l', 'o', 'n'):
			if i == 'l' or i == 'o':
				ans = min(ans, d[i] // 2)
			else:
				ans = min(ans, d[i])
		return ans


class Solution:

	def maxInstance(self, s: str) -> int:
		d = {}
		for i in s:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		if 'b' in d and 'l' in d and ('a' in d) and ('o' in d) and ('n' in d):
			su = min(d['l'], d['o']) // 2
			if su <= d['a'] and su <= d['b'] and (su <= d['n']):
				return su
			return min(d['a'], d['b'], d['n'])
		else:
			return 0


class Solution:

	def maxInstance(self, s: str) -> int:
		dic = {}
		for char in s:
			if char in dic:
				dic[char] += 1
			else:
				dic[char] = 1
		ans = min(dic['b'], dic['a'])
		ans = min(dic['l'] / 2, ans)
		ans = min(dic['o'] / 2, ans)
		ans = min(dic['n'], ans)
		return int(ans)


class Solution:

	def maxInstance(self, s: str) -> int:
		l = []
		c = s.count('b')
		c1 = s.count('a')
		c2 = s.count('l')
		c2 = c2 // 2
		c3 = s.count('o')
		c3 = c3 // 2
		c4 = s.count('n')
		l = [c, c1, c2, c3, c4]
		return min(l)


class Solution:

	def maxInstance(self, s: str) -> int:
		h = {'b': 0, 'a': 0, 'l': 0, 'o': 0, 'n': 0}
		ans = 0

		def Check(hashmap):
			if h['b'] >= 1 and h['a'] >= 1 and (h['l'] >= 2) and (h['o'] >= 2) and (h['n'] >= 1):
				h['b'] -= 1
				h['a'] -= 1
				h['l'] -= 2
				h['o'] -= 2
				h['n'] -= 1
				return True
		for i in s:
			if i in h:
				h[i] += 1
			if Check(h):
				ans += 1
		return ans


class Solution:

	def maxInstance(self, s: str) -> int:
		mp = {}
		for i in s:
			mp[i] = mp[i] + 1 if i in mp else 1
		return min(mp['b'], mp['a'], mp['l'] // 2, mp['o'] // 2, mp['n'])


class Solution:

	def maxInstance(self, s: str) -> int:
		x = list(s)
		ll = {}
		for i in x:
			if i in ll.keys():
				ll[i] = ll[i] + 1
			else:
				ll[i] = 1
		ans = {}
		for i in ll:
			if i in ['b', 'a', 'l', 'o', 'n']:
				if i in ['l', 'o']:
					ans[i] = int(ll[i] / 2)
				else:
					ans[i] = ll[i]
		if len(ans) == 5:
			return min(ans.values())
		else:
			return 0


class Solution:

	def maxInstance(self, s: str) -> int:
		x = []
		instance = 0
		for i in ('b', 'a', 'l', 'o', 'n'):
			if i in s:
				x.append(i)
		count_of_b = s.count('b')
		count_of_a = s.count('a')
		count_of_l = s.count('l')
		count_of_o = s.count('o')
		count_of_n = s.count('n')
		if count_of_b == 0 or count_of_a == 0 or count_of_l == 0 or (count_of_o == 0) or (count_of_n == 0):
			return -1
		for t in range(count_of_b):
			count_of_b -= 1
			count_of_a -= 1
			count_of_l -= 2
			count_of_o -= 2
			count_of_n -= 1
			if count_of_b < 0 or count_of_a < 0 or count_of_l < 0 or (count_of_o < 0) or (count_of_n < 0):
				return instance
			instance += 1
		return instance


class Solution:

	def maxInstance(self, s: str) -> int:
		mp = {}
		minimum = len(s)
		for i in s:
			if i in mp:
				mp[i] += 1
			else:
				mp[i] = 1
		for i in mp:
			if minimum > mp[i] and i in ['b', 'a', 'n']:
				minimum = mp[i]
			if i in ['l', 'o'] and minimum > mp[i] // 2:
				minimum = mp[i] // 2
		return minimum


class Solution:

	def maxInstance(self, s: str) -> int:
		count = [0] * 26
		for c in s:
			count[ord(c) - ord('a')] += 1
		return min(count[ord('b') - ord('a')], count[ord('a') - ord('a')], count[ord('l') - ord('a')] // 2, count[ord('o') - ord('a')] // 2, count[ord('n') - ord('a')])


class Solution:

	def maxInstance(self, s: str) -> int:
		d = {'b': 0, 'a': 0, 'l': 0, 'o': 0, 'n': 0}
		for i in s:
			if d.get(i, None) != None:
				d[i] += 1
		l = []
		for i in d.keys():
			if i == 'l' or i == 'o':
				l.append(d[i] // 2)
			else:
				l.append(d[i])
		return min(l)


class Solution:

	def maxInstance(self, s: str) -> int:
		d = {'b': 0, 'a': 0, 'l': 0, 'l': 0, 'o': 0, 'o': 0, 'n': 0}
		for i in s:
			if i in d:
				d[i] += 1
		t = list(d.values())
		if len(t) == 5:
			d['l'] = d['l'] / 2
			d['o'] = d['o'] / 2
			return int(min(list(d.values())))
		return 0


class Solution:

	def maxInstance(self, s: str) -> int:
		count = 0
		b = s.count('b')
		a = s.count('a')
		l = s.count('l')
		o = s.count('o')
		n = s.count('n')
		while not b < 1 and (not n < 1) and (not a < 1) and (not l < 2) and (not o < 2):
			count += 1
			(b, a, l, o, n) = (b - 1, a - 1, l - 2, o - 2, n - 1)
		return count


class Solution:

	def maxInstance(self, s: str) -> int:
		char_count = {}
		for char in s:
			if char in ['b', 'a', 'l', 'o', 'n']:
				char_count[char] = char_count.get(char, 0) + 1
		if len(char_count) < 5:
			return 0
		char_count['l'] //= 2
		char_count['o'] //= 2
		return min(char_count.values())


class Solution:

	def maxInstance(self, s: str) -> int:
		ballon = {'b': 0, 'a': 0, 'l': 0, 'o': 0, 'n': 0}
		for i in s:
			if i in 'balon':
				ballon[i] += 1
		ballon['l'] //= 2
		ballon['o'] //= 2
		lis_ballon = []
		for i in ballon:
			lis_ballon.append(ballon[i])
		lis_ballon.sort()
		return lis_ballon[0]


class Solution:

	def maxInstance(self, s: str) -> int:
		r = []
		r.append(s.count('b'))
		r.append(s.count('a'))
		r.append(s.count('l') // 2)
		r.append(s.count('o') // 2)
		r.append(s.count('n'))
		return min(r)


class Solution:

	def maxInstance(self, s: str) -> int:
		li = []
		if 'b' in s and 'a' in s and ('l' in s) and ('o' in s) and ('n' in s):
			li.append(s.count('b') // 1)
			li.append(s.count('a') // 1)
			li.append(s.count('l') // 2)
			li.append(s.count('o') // 2)
			li.append(s.count('n') // 1)
			return min(li)
		else:
			return 0


class Solution:

	def maxInstance(self, s: str) -> int:
		balloon = 'balloon'
		count = {}
		for ch in s:
			if ch in count:
				count[ch] += 1
			else:
				count[ch] = 1
		res = float('inf')
		for ch in balloon:
			if ch in count:
				res = min(res, count[ch] // balloon.count(ch))
			else:
				return -1
		return res


class Solution:

	def maxInstance(self, s: str) -> int:
		balloon = 'balloon'
		count = [0] * 26
		for ch in s:
			count[ord(ch) - ord('a')] += 1
		res = float('inf')
		for ch in balloon:
			res = min(res, count[ord(ch) - ord('a')] // balloon.count(ch))
		return res