Given a string text, use its characters to form as many instances of the word "balloon" as possible. Each character in text can be used at most once. Return the maximum number of instances that can be formed.
Function Signature
def max_number_of_balloons(text: str) -> int:
Rules
-
Characters can come from any positions in
text
; their order in
text
does not matter.
-
Each character of
text
belongs to at most one instance.
-
If not even one instance can be formed, return 0.
Constraints
-
1 <= len(text) <= 10^4
-
text
consists of lowercase English letters only.
Examples
Input: text = "nlaebolko"
Output: 1
The string has one b, one a, two l, two o and one n, exactly enough for one "balloon". The e and k are left over.
Input: text = "loonbalxballpoon"
Output: 2
The string has two b, two a, four l, four o and two n, enough for two instances. The x and p are left over.
Input: text = "lloonan"
Output: 0
There is no b in the string, so no instance can be formed.