#1296

Divide Array in Sets of K Consecutive Numbers

specialist · 730 · lc medium +31 · verified · 59.1% accepted · 1,982 likes · top 56%

Description

Determine whether the integer array nums can be partitioned entirely into groups, where each group contains exactly k consecutive integers.

Return true if such a partition is possible, otherwise return false.

Example 1:

Input: nums = [1,2,3,3,4,4,5,6], k = 4
Output: true
Explanation: Array can be divided into [1,2,3,4] and [3,4,5,6].

Example 2:

Input: nums = [3,2,1,2,3,4,3,4,5,9,10,11], k = 3
Output: true
Explanation: Array can be divided into [1,2,3] , [2,3,4] , [3,4,5] and [9,10,11].

Example 3:

Input: nums = [1,2,3,4], k = 3
Output: false
Explanation: Each array should be divided in subarrays of size 3.

Code

1
2
3