Talentd
FleetCode

3231. Minimum Number of Increasing Subsequence to Be Removed

Hard47.9% acceptancePremium elsewhere, free here

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.

Example 1:

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

Output: 3

Explanation:

We remove subsequences [1, 2], [3, 4], [5].

Example 2:

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

Output: 1

Example 3:

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

Output: 5

Constraints:

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

Hints open one at a time

Hint 1
Find the longest non-increasing subsequence.
Hint 2
No two elements of this sequence can be removed in one operation.
Hint 3
Try to prove that the answer is equal to the length of this sequence.
5:29
Still stuck?Read the written solution, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def solve(self):
3 pass
4
Starter codePython 3Spaces: 4
Examples
Input
[5,3,1,4,2]
Input
[1,2,3,4,5]
Input
[5,4,3,2,1]
Your code is saved on this device.Solution