---
# System prepended metadata

title: 1671. Minimum Number of Removals to Make Mountain Array
tags: [Leetcode, Dynamic Programming, Hard, Three Pass, Greedy]

---

# 1671. Minimum Number of Removals to Make Mountain Array
###### tags: `Leetcode` `Hard` `Greedy` `Dynamic Programming` `Three Pass`
Link: https://leetcode.com/problems/minimum-number-of-removals-to-make-mountain-array/description/
## 思路
## Code
```java=
class Solution {
    public int minimumMountainRemovals(int[] nums) {
        int n = nums.length;
        int[] front = new int[n];
        int[] end = new int[n];
        Arrays.fill(front, 1);
        Arrays.fill(end, 1);
        for(int i=1; i<n; i++){
            for(int j=0; j<i; j++){
                if(nums[j]<nums[i]) front[i] = Math.max(front[i], front[j]+1);
            }
        }
        for(int i=n-1; i>=0; i--){
            for(int j=n-1; j>i; j--){
                if(nums[j]<nums[i]) end[i] = Math.max(end[i], end[j]+1);
            }
        }
        int ans = 0;
        for(int i=1; i<n-1; i++){
            if(front[i]==1 || end[i]==1) continue;
            ans = Math.max(ans, front[i]+end[i]-1);
        }
        return n-ans;
    }
}
```