1671. Minimum Number of Removals to Make Mountain Array Hard

@problem@discussion
#Array#Binary Search#Dynamic Programming#Greedy



1/**
2 * [1671] Minimum Number of Removals to Make Mountain Array
3 *
4 * You may recall that an array arr is a mountain array if and only if:
5 * 
6 * 	arr.length >= 3
7 * 	There exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:
8 * 	
9 * 		arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
10 * 		arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
11 * 	
12 * 	
13 * 
14 * Given an integer array nums​​​, return the minimum number of elements to remove to make nums​​​ a mountain array.
15 *  
16 * Example 1:
17 * 
18 * Input: nums = [1,3,1]
19 * Output: 0
20 * Explanation: The array itself is a mountain array so we do not need to remove any elements.
21 * 
22 * Example 2:
23 * 
24 * Input: nums = [2,1,1,5,6,2,3,1]
25 * Output: 3
26 * Explanation: One solution is to remove the elements at indices 0, 1, and 5, making the array nums = [1,5,6,3,1].
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	3 <= nums.length <= 1000
32 * 	1 <= nums[i] <= 10^9
33 * 	It is guaranteed that you can make a mountain array out of nums.
34 * 
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/minimum-number-of-removals-to-make-mountain-array/
39// discuss: https://leetcode.com/problems/minimum-number-of-removals-to-make-mountain-array/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44    pub fn minimum_mountain_removals(nums: Vec<i32>) -> i32 {
45        0
46    }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn test_1671() {
57    }
58}
59


Back
© 2025 bowen.ge All Rights Reserved.