DIY: Divide Array in Sets of K Consecutive Numbers

Solve the interview question "Divide Array in Sets of K Consecutive Numbers" yourself in this lesson.

We'll cover the following

Problem statement

In this challenge, you are given an array of integers nums and a positive integer k. You have to determine whether it is possible to divide the elements of the array into groups of k consecutive numbers.

Input

The inputs will be an array of integers called nums and a positive integer k. The following is an example input:

[3,2,1,2,3,4,3,4,5,9,10,11]
3

Output

The output will be True if it is possible to divide the array’s elements into groups of k consecutive numbers. Otherwise, the output will be False. The above-mentioned inputs will give the following output:

True

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.