MediumGreedy · Hash Map · Heap

Hand of Straights

Each hand[i] is a card value. Return true if the cards can be split into groups of exactly groupSize cards whose values are consecutive (each 1 more than the last).

hand = [1,2,4,2,3,5,3,4], groupSize = 4 → true ([1,2,3,4], [2,3,4,5])hand = [1,2,3,3,4,5,6,7], groupSize = 4 → false

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Variables

The data structures the code is building

The cards

Columns = cards left of each value; finished groups collect below

Time and space complexity

n = len(hand). The highlighted row is the solution being traced.

Keyboard: ← → step, Space play or pause. Up to 16 cards with values from 0 to 99, groupSize from 1 to 8, and values close enough to fit 17 columns.