Problem · Array
Minimum Removals for a Nice Array
Learn this problemProblem statement
An array is nice when removing exactly one of its elements leaves a strictly increasing array.
Given an array of positive integers nums, delete the minimum number of elements, without reordering the remaining elements, so that the remaining array is nice. Return that minimum number.
The remaining nice array must contain at least two elements.
Function
minimumRemovalsForNice(nums: int[]) → intExamples
Example 1
nums = [4,1,2,3]return = 0The whole array is already nice because deleting 4 leaves 1, 2, 3.
Example 2
nums = [5,4,3,2,1]return = 3A longest increasing subsequence has length 1, so at most two elements can remain in a nice array.
Constraints
2 <= nums.length <= 2000001 <= nums[i] <= 10^9- Deleting an element preserves the relative order of all remaining elements.