Divide Array Into Increasing Sequences - Problem
Given an integer array nums sorted in non-decreasing order and an integer k, return true if this array can be divided into one or more disjoint increasing subsequences of length at least k, or false otherwise.
A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. Two subsequences are disjoint if they do not share any elements.
An increasing subsequence means each element is strictly greater than the previous one.
Input & Output
Example 1 — Valid Partition
$
Input:
nums = [1,2,3,3,4,5], k = 3
›
Output:
true
💡 Note:
We can form one increasing subsequence [1,2,3,4,5] of length 5 ≥ 3 by using elements at positions [0,1,2,4,5], leaving the duplicate 3 unused.
Example 2 — Too Small Array
$
Input:
nums = [1,2], k = 3
›
Output:
false
💡 Note:
Array length is 2, but we need subsequences of length at least 3, so it's impossible.
Example 3 — Frequency Too High
$
Input:
nums = [1,1,1,2], k = 2
›
Output:
false
💡 Note:
Number 1 appears 3 times, but with k=2, we can have at most ⌈4/2⌉ = 2 occurrences of any number.
Constraints
- 1 ≤ nums.length ≤ 105
- -105 ≤ nums[i] ≤ 105
- nums is sorted in non-decreasing order
- 1 ≤ k ≤ nums.length
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code