Find Common Characters
Real-world version: Tiles Every Rack Can SupplyThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def shared_tiles(racks: list[str]) -> list[str]:public List<String> sharedTiles(String[] racks)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Verifying an Alien DictionaryReal-world version: Catalogue Order Under a Custom Glyph SequenceEasy
- Destination CityReal-world version: Last Stop On The Courier RunEasy
- Find Words That Can Be Formed by CharactersReal-world version: Signs Spellable From A Tile TrayEasy
- Sort the PeopleReal-world version: Season Leaderboard From Two Parallel ListsEasy