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 where hand[i] is the value written on the i-th card and an integer groupSize, return true if she can rearrange the cards, or false otherwise.
Example 1
Input: hand = [1,2,3,6,2,3,4,7,8], groupSize = 3
Output: true
Explanation: The hand splits into [1,2,3], [2,3,4], [6,7,8] — all consecutive groups of size 3.
Example 2
Input: hand = [1,2,3,4,5], groupSize = 4
Output: false
Explanation: There are 5 cards, and 5 cannot be split into groups of 4, so the rearrangement is impossible.
Example 3
Input: hand = [8,10,12], groupSize = 3
Output: false
Explanation: The groups need 3 consecutive values, but 8, 10 and 12 have gaps (9 and 11 are missing).
The smallest remaining card must start a group, and that forces the next groupSize-1 consecutive values. Repeatedly consume such runs; if any required value is missing, it's impossible.
Run checks all cases above. Submit evaluates all test cases.