All problems
0660EasyArrayHash TableString

Tiles Every Rack Can Supply

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1002Find Common Characters

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

Each player in a word game holds a rack of letter tiles. racks[i] is a string listing the tiles on the i-th rack, one lowercase letter per tile.

The umpire wants the multiset of tiles that every rack can supply at the same time. Copies count: if a letter is on one rack three times and on another rack twice, then only two copies of it can come from every rack.

Return those tiles as a list of one-letter strings, one entry per copy. Any order is accepted. Return an empty list when no letter sits on every rack.

Examples

Example 1

Input
racks = ["ppqqr", "pqrst", "zpqq"]
Output
["p", "q"]

Letter p sits on all three racks once each, so one copy is available. Letter q sits twice, once and twice, so one copy is available. Letter r is missing from the third rack, and no other letter is on all three.

Example 2

Input
racks = ["eexz", "zex"]
Output
["e", "x", "z"]

The first rack has two e tiles but the second has only one, so one e can come from both. Letters x and z are on each rack once.

Example 3

Input
racks = ["hjk", "wxy"]
Output
[]

The two racks share no letter at all, so the answer is the empty list.

Constraints

  • 1 <= racks.length <= 100
  • 1 <= racks[i].length <= 100
  • racks[i] consists of lowercase English letters.

The values you return may be in any order.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def shared_tiles(racks: list[str]) -> list[str]:
Java
public List<String> sharedTiles(String[] racks)
September 7
Apply