> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Maximum Number of Balloons Python Solution

> Tested Python solution for LeetCode 1189 with 16 pytest cases. Generate a practice environment with lcpy.

LeetCode 1189, [Easy](/catalog/easy). Topics: [Hash Table](/catalog/topics/hash-table), [String](/catalog/topics/string), [Counting](/catalog/topics/counting). [View on LeetCode](https://leetcode.com/problems/maximum-number-of-balloons/description/).

Generate this problem as a practice environment: tested reference solution, 16 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 1189   # by problem number
lcpy gen -s maximum_number_of_balloons   # by problem name
```

## Problem

Given 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.

### Examples

![Example 1](https://assets.leetcode.com/uploads/2019/09/05/1536_ex1_upd.JPG)

```
Input: text = "nlaebolko"
Output: 1
```

![Example 2](https://assets.leetcode.com/uploads/2019/09/05/1536_ex2_upd.JPG)

```
Input: text = "loonbalxballpoon"
Output: 2
```

```
Input: text = "leetcode"
Output: 0
```

### Constraints

* `1 <= text.length <= 10^4`
* `text` consists of lower case English letters only.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_number_of_balloons/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/maximum_number_of_balloons/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from collections import Counter


class Solution:
    # Time: O(len(text))
    # Space: O(1)
    def max_number_of_balloons(self, text: str) -> int:
        counts = Counter(text)
        return min(counts["b"], counts["a"], counts["l"] // 2, counts["o"] // 2, counts["n"])
```

## Complexity

| Time | Space |
| - | - |
| O(len(text)) | O(1) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.