DIY: Split Array into Consecutive Subsequences
Solve the interview question "Split Array into Consecutive Subsequences" in this lesson.
We'll cover the following
Problem statement
Given an array sorted in ascending order, determine if it’s possible to split the array into one or more subsequences such that each subsequence consists of consecutive integers and has a length of at least 3 integers.
Input
The input will be a list of sorted numbers. The following is an example input:
[1, 2, 3, 3, 4, 4, 5, 5]
Output
The output should show whether the numbers can make consecutive subsequences of a length 3 or more. For the above input, the output should be:
true
Coding exercise
For this coding exercise, you need to implement the isPossible(arr)
function, where arr
is the sorted list of numbers. The function should return either true
or false
depending on whether the consecutive subsequences exist or not.
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.