Show problems as
Classic problem #1189EasyHash TableStringCounting

Maximum Number of Balloons

Real-world version: Kettle Signs from the Tile Tray
Tracked in this browser only
Read Maximum Number of Balloons on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A sign shop keeps loose letter tiles in one tray. The string tiles gives the letter printed on each tile in the tray, one lowercase letter per tile.

A finished sign spells the word kettle, so laying out one sign takes a k tile, two e tiles, two t tiles and an l tile. A tile can only be laid into one sign: once it is used it is gone for the rest of the run, and tiles printed with any other letter are no help at all.

Return how many finished signs the shop can lay out from the tray it has.

Examples

Example 1

Input
tiles = "ttlleekkeettll"
Output
2

The tray holds two k tiles, four e tiles, four t tiles and four l tiles. Two signs use two k, four e, four t and two l tiles, which the tray covers, and two l tiles are left over.

Example 2

Input
tiles = "kkeeeetttlll"
Output
1

One sign takes a k, two e, two t and an l tile. That leaves a k, two e, a t and two l tiles sitting unused in the tray.

Example 3

Input
tiles = "settlement"
Output
0

There is no k tile anywhere in the tray, so no sign can be laid out.

Constraints

  • 1 <= tiles.length <= 10^4
  • tiles consists of lowercase English letters only

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def kettle_signs(tiles: str) -> int:
Java
public int kettleSigns(String tiles)