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 = 3
Output:true
Explanation:

Groups: [1,2,3],[2,3,4],[6,7,8].

Input:hand = [1], groupSize = 3
Output:true
Explanation:

Edge case with a single-element array.

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

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⁴

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!