Hand of Straights
Problem
You hold a hand of cards, given as an integer array hand where each value is a card's rank. You want to rearrange the entire hand into groups of exactly groupSize cards each, where every group consists of consecutive ranks (for example 4, 5, 6). Every card must be used in exactly one group. Return True if such an arrangement exists and False otherwise.
- The hand has between 1 and 50,000 cards.
- Ranks are integers between 0 and 2,000,000,000, so they cannot be used as array indices.
groupSizeis between 1 and the number of cards.
Examples
hand = [5, 7, 6, 9, 8, 6, 10, 7, 8], groupSize = 3→True. Groups:[5, 6, 7],[6, 7, 8],[8, 9, 10].hand = [2, 3, 4, 5, 6, 7, 8], groupSize = 4→False. Seven cards cannot be split into groups of four.hand = [4, 4, 5, 6], groupSize = 2→False. The two 4s each need a 5, but there is only one 5.
Hints
- Consider the smallest card still in your hand. Is there any choice about which group it belongs to?
- Once the smallest card must start a group, which other cards are forced into that group?
- Count the cards, walk ranks in increasing order, and for each rank with a nonzero count, subtract that count from the next
groupSizeranks; fail if any is short.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.