- Sort hand first.
- Use map to record frequencies.
- For each head, get its
countin map, and shift the array until
hand !== head.
count === 0, it means that we’ve used all of it before, jump to next iteration.
- Contruct consecutives based on the count, and if needed cards’ count is smaller than what we need, return false.
mapwhile constructing cards.
Alice has some number of cards and she wants to rearrange the cards into groups so that each group is of size
groupSize, and consists of
groupSize consecutive cards.
Given an integer array
hand[i] is the value written on the
ith card and an integer
true if she can rearrange the cards, or false otherwise.
Input: hand = [1,2,3,6,2,3,4,7,8], groupSize = 3