Hand of Straights
Given array hand and groupSize, check if cards can form groups of consecutive cards Each group must have groupSize consecutive cards Example: hand = [1,2,3,6,2,3,4,7,8], groupSize = 3 => true Can form [1,2,3], [2,3,4], [6,7,8]
Hand of Straights looks straightforward, but it quietly checks whether you reach for the right lookup structure. Interviewers love it because it reveals your data-structure instincts and your edge-case discipline. Watch your edge cases around repeats, and be clear about what your map is storing.
Examples
You write
is_n_straight_hand(hand: List[int], group_size: int)
Example 1
- Input
- hand = [1,2,3,6,2,3,4,7,8], groupSize = 3
- returns
- true
Example 2
- Input
- hand = [1,2,3,4,5], groupSize = 4
- returns
- false
The pattern behind it
Arrays & Hashing
I reach for it when
- You catch yourself scanning the array again for every element.
- The problem asks about duplicates, pairs, counts or groups.
Say this before you type. Say what the key is and what the value remembers, before you write the loop.
All 127 Arrays & Hashing problemsGreedy
I reach for it when
- A locally best choice looks safe.
- You sort first, then sweep once.
Say this before you type. Say the greedy choice, then say why swapping it for another choice cannot do better.
All 17 Greedy problems
Meet Coco
Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.