Given an array and an integer k, determine whether the array can be divided into sets of k consecutive numbers. A frequency-aware counting strategy over the sorted values is the standard solution.
nums = array of integers, k = size of each consecutive group
true if the array can be divided into consecutive sets of size k
Example 1:
Input:
nums = [1,2,3,3,4,4,5,6] k = 4
Output:
true
Explanation:
The array can be split into [1,2,3,4] and [3,4,5,6].
Example 2:
Input:
nums = [3,3,2,2,1,1] k = 3
Output:
true
Explanation:
Two groups [1,2,3] can be formed.