Split Array into Consecutive Subsequences

Medium

Description

Given sorted array, split into one or more subsequences where each has length >= 3 and consecutive integers.

Examples

Input:nums = [1,2,3,3,4,5]
Output:true
Explanation:

Split into [1,2,3] and [3,4,5].

Input:nums = [1]
Output:true
Explanation:

Edge case with a single-element array.

Input:nums = [1,2,3,4,4,5]
Output:false
Explanation:

Cannot form valid consecutive subsequences. There are [1,2,3,4] and [4,5], but the second subsequence only has length 2, which violates the minimum length requirement of 3.

Constraints

  • 1 ≤ nums.length ≤ 10⁴

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!