Return whether the hand can be rearranged into groups of groupSize consecutive values.
Before you code
The smallest remaining card has no smaller card to follow, so in any valid arrangement it starts a group. That makes the first choice forced.
Hints
- If the hand size isn't divisible by groupSize, return false.
- Count cards; repeatedly take the smallest value with a positive count and remove one each of value, value + 1, … value + groupSize − 1.
- If any is missing, return false. A sorted list of keys or a heap finds the smallest.
Production & complexity notes
When solving Hand of straights on LeetCode (medium), always state your loop or recursion invariant before writing code. Verify how your chosen data structure behaves on degenerate inputs (single-element inputs, all-duplicate keys, strictly monotonic sequences, or maximum constraint sizes up to $10^5$ elements). In production interviews, pair your implementation with an explicit time and auxiliary space complexity proof, explain why alternative brute-force approaches violate the latency budget, and trace how cache locality and memory allocation overhead affect wall-clock throughput on real hardware. Review the step-by-step memory trace in Exchange arguments to reinforce the underlying pattern.
What it practices
A forced first choice, from Exchange arguments.