Remove as few elements as possible from nums, preserving the order of the remaining elements, to obtain a mountain array.
A mountain array has at least three elements. Its values strictly increase up to an interior peak and then strictly decrease. Both sides of the peak must contain at least one element, and equal adjacent values are not allowed.
Return the minimum number of removals. The input is guaranteed to contain a valid mountain subsequence.
Example 1:
Input: nums = [1,4,2]
Output: 0Explanation: The values already increase from 1 to the interior peak 4 and then decrease to 2, so no removal is needed.
Example 2:
Input: nums = [1,3,3,2]
Output: 1Explanation: Remove either occurrence of 3 to obtain [1,3,2]. At least one removal is necessary because the original array has equal adjacent peak values.
Example 3:
Input: nums = [4,1,3,2]
Output: 1Explanation: Remove the leading 4 to obtain [1,3,2]. This is a mountain, while the original array is not, so exactly one removal is required.
Constraints:
3 <= nums.length <= 10001 <= nums[i] <= 1000000000- A mountain subsequence is guaranteed to exist.