Is a 14-tile mahjong hand a winning hand?
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Google's first round (coding), last asked Mar 2026. It tests backtracking and counting.
A mahjong-style hand has 14 tiles of a single suit, each a value from 1 to 9. The hand is winning if all 14 tiles can be split into one pair (two identical tiles) and four melds, where each meld is either a triplet (three identical tiles) or a sequence (three consecutive values, such as 2, 3, 4). Every tile is used exactly once, and the order of the input does not matter.
Interface
Unless you agree on a different interface with the interviewer, assume:
is_winning(tiles: list[int]) -> bool
Example
is_winning([1,1,1,2,3,4,2,3,4,5,6,7,9,9]) -> True # pair 9-9; 1-1-1; 2-3-4; 2-3-4; 5-6-7
is_winning([2,2,2,3,3,3,4,4,4,5,5,5,9,9]) -> True # pair 9-9 and four triplets
is_winning([1,1,2,2,3,3,4,4,5,5,6,6,7,7]) -> True # pair 4-4; 1-2-3; 1-2-3; 5-6-7; 5-6-7
is_winning([1,2,3,4,5,6,7,8,9,1,2,3,5,7]) -> False
Constraints
-
len(tiles) == 14;1 <= tiles[i] <= 9. A value may appear more than four times.
Clarifying questions
- One suit only, or several suits plus honour tiles?
- Can a value appear more than four times?
- Do special hands count (seven pairs, thirteen orphans)?
What a strong answer covers
- Count tiles per value (9 counters) instead of searching over permutations.
- Try each value with a count of at least 2 as the pair. For the rest, take the smallest remaining value: it must start a triplet or a sequence (it cannot be in the middle of one), so try both and recurse. The search is tiny: at most 9 pair choices with a few branches each.
- Why handling the smallest value first makes the search complete and avoids duplicates.
- Tests: all triplets, all sequences, a hand where a greedy triplet choice fails but a sequence works, no possible pair.
Follow-ups
- Several suits plus honour tiles, which can only form triplets.
- Given 13 tiles, list every tile that would complete a winning hand.
- Count the number of distinct ways to split a winning hand.
Where it's asked
- Google · First round: coding · Last asked Mar 202645 min · Coding in a Google Doc, no syntax highlighting or autocomplete · No AI
What it tests
backtracking · counting
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
