Description
Given cards and group size W, return true if cards can be rearranged into groups of W consecutive cards.
Examples
Input:
hand = [1,2,3,6,2,3,4,7,8], groupSize = 3Output:
trueExplanation:
Groups: [1,2,3],[2,3,4],[6,7,8].
Input:
hand = [1], groupSize = 3Output:
trueExplanation:
Edge case with a single-element array.
Input:
hand = [1,2,3,4,5], groupSize = 2Output:
falseExplanation:
There are 5 cards but need groups of 2. Since 5 is not divisible by 2, it's impossible to form complete groups of consecutive pairs.
Constraints
- •
1 ≤ hand.length ≤ 10⁴