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
Minimum Increasing Subsequences to Remove INPUT Array: nums 5 i=0 3 i=1 4 i=2 2 i=3 1 i=4 Find minimum operations to empty array by removing strictly increasing subsequences Value Distribution 5 3 4 2 1 ALGORITHM STEPS 1 Initialize Create empty list for subsequence tails 2 Process Each Element Binary search to find smallest tail >= current 3 Update Tails Replace found tail or add new subsequence 4 Count Subsequences Tails list size = answer Trace: tails[] Process 5: [5] Process 3: [3,5] Process 4: [3,4] Process 2: [2,4] Process 1: [1,4] Size = 2 FINAL RESULT Two Increasing Subsequences: Subsequence 1 1 2 3 4 Subsequence 2 5 OUTPUT 2 Minimum operations = 2 [OK] Array becomes empty after 2 removals Key Insight: This problem is equivalent to finding the Longest Non-Increasing Subsequence (LDS)! Each element in an increasing subsequence must come from a different "level" of decreasing elements. Using greedy with binary search, we maintain tails of active subsequences. Time: O(n log n), Space: O(n) TutorialsPoint - Minimum Number of Increasing Subsequence to Be Removed | Greedy with Binary Search
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