mediumGreedyGoogle
Card Flush Builder
A card player checks if their hand can be grouped into runs of consecutive values of a fixed length.
Given a hand and a group size k, return true iff the hand can be partitioned into groups of k consecutive integers.
Choose approach
1
02
13
26
32
43
54
67
78
8Mapcount
1→0
2→1
3→1
4→1
6→1
7→1
8→1
1/4
Narrationstep 1 of 4
Formed 1 straights starting at 1.
Variables
start=1
c=1
How to think about it
- n % k != 0 is an immediate 'false'.
- Smallest value must start exactly count[smallest] groups.
Edge cases to catch in interview
- Empty hand -> true.
- k = 1 -> always true.
Examples
Example 1
false{"hand":[1,2,3,4,5],"groupSize":4,"values":[1,2,3,4,5]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed