977. Minimum Number of Increasing Subsequence to Be Removed

You are given an array of integers nums. In one operation, you can remove any subsequence from the array as long as the subsequence is strictly increasing (each selected element is less than the element that follows it).

Your goal is to determine the minimum number of operations needed to remove all elements from the array.

Example 1:

Input : nums = [4, 2, 1, 3]

Output : 3

Explanation :

One way to empty the array is:

  • Remove [2, 3] (elements at indices 1 and 3) in the first operation.
  • Remove [1] in the second operation.
  • Remove [4] in the final operation.

Example 2:

Input : nums = [1, 2, 3, 4]

Output : 1

Explanation :

The entire array is strictly increasing, so it can be removed in a single operation.

Now Your Turn!

Pick the correct output for the given input

Input : nums = [8, 6, 4, 2]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= nums.length <= 105
  • 1 <= nums[i] <= 105

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
int minOperations(vector<int>& a) {
// Your code goes here
}
};
Test Case

Input:

Nums