Minimum Number of Increasing Subsequence to Be Removed - Problem
Given an array of integers nums, you are allowed to perform the following operation any number of times:
Remove a strictly increasing subsequence from the array.
Your task is to find the minimum number of operations required to make the array empty.
A strictly increasing subsequence is a subsequence where each element is greater than the previous one.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [5,3,4,2,1]
›
Output:
4
💡 Note:
We need to partition the array into strictly increasing subsequences. We can remove [3,4] and then [5], [2], [1] separately. This requires 4 operations total.
Example 2 — Already Sorted
$
Input:
nums = [1,2,3,4,5]
›
Output:
1
💡 Note:
The entire array is already strictly increasing, so we can remove it all in one operation.
Example 3 — All Same Elements
$
Input:
nums = [5,5,5,5]
›
Output:
4
💡 Note:
Since we need strictly increasing subsequences, each element of value 5 must be removed separately, requiring 4 operations.
Constraints
- 1 ≤ nums.length ≤ 105
- 1 ≤ nums[i] ≤ 109
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code