Split Array into Consecutive Subsequences
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an integer array nums sorted in **non-decreasing** order. Decide whether you can split all of its elements into one or more subsequences such that:
- each subsequence is a run of consecutive integers, each exactly one more than the previous, and
- each subsequence has length **at least 3**.
Every element must go into exactly one subsequence. Return true if such a split exists and false otherwise. Aim for O(n) time.
Examples
Constraints
- 1 <= nums.length <= 10^4
- -1000 <= nums[i] <= 1000
- nums is sorted in non-decreasing order
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.