Hand of Straights

mediumGreedycount map + greedily build runs from smallest cardSolve on LeetCode#846

Part of Practice: Clever Commitments

You hold a hand of cards, given as an integer array hand, and a number groupSize. Decide whether the whole hand can be split into groups where every group is exactly groupSize consecutive cards (like 3, 4, 5). Every card must be used in exactly one group. Return true if such a split exists, false otherwise.

Constraints that matter: up to 10,000 cards with values up to a billion, and duplicates are allowed — the same value can appear in several different groups. If the hand size is not divisible by groupSize, no split can exist.

Examples

Input:
hand = [1, 2, 3, 6, 2, 3, 4, 7, 8], groupSize = 3
Output:
true

The hand splits into [1, 2, 3], [2, 3, 4], and [6, 7, 8].

Input:
hand = [1, 2, 3, 4, 5], groupSize = 4
Output:
false

Five cards cannot be split into groups of four.

Input:
hand = [8, 10, 12], groupSize = 1
Output:
true

With groups of size 1, any hand works — each card is its own group.

Hints

One at a time — struggle first, peek second.

Your thinking space — verify on LeetCode, then mark it.