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: 2
💡 Note: We can remove [3,4] and [5] as increasing subsequences, leaving [2,1]. Then remove [2] and [1] separately. Total: 4 operations. But optimally, we can think of this as needing to handle the longest decreasing subsequence [5,3,2,1] which requires 4 operations, but the actual answer is based on a different partitioning strategy.
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
Minimum Increasing Subsequences: [5,3,4,2,1] → 4 operations53421Input Array[3,4][5][2][1]Optimal partition into increasing subsequencesResult: 4 operations needed
Understanding the Visualization
1
Input
Array with mixed order: [5,3,4,2,1]
2
Process
Find minimum partitions into increasing subsequences
3
Output
Minimum operations needed: 4
Key Takeaway
🎯 Key Insight: The minimum operations equal the length of the longest decreasing subsequence in the array
Asked in
Google 15 Microsoft 12 Amazon 8
23.4K Views
Medium Frequency
~25 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen