You are given an integer array that is sorted in non-decreasing order. Decide whether it is possible to partition all of its elements into one or more subsequences, where each subsequence is a run of consecutive increasing integers.
Every subsequence must have a length of at least three. Return true if such a partition exists and false otherwise.
Example 1
Input: nums = [1,2,3,3,4,5]
Output: true
The array splits into [1,2,3] and [3,4,5], each a consecutive run of length 3.
Example 2
Input: nums = [1,2,3,4,4,5]
Output: false
No valid split exists: any attempt leaves a leftover run shorter than three consecutive integers.
Constraints
1 <= nums.length <= 10^4-1000 <= nums[i] <= 1000nums is sorted in non-decreasing order.See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI