15% off all plans & roadmaps Use code
See plansLeetCode 1671 · Solution & editorial
You may recall that an array arr is a mountain array if and only if:
Minimum Number of Removals to Make Mountain Array is a Dynamic Programming (DP) Patterns problem, in the Longest Increasing Subsequence (LIS) subpattern. The pattern covers fibonacci, Kadane, knapsack, LCS, LIS, edit distance, grid paths, and word break
Find LIS using DP and binary search optimization. O(n log n) solution.
The reference solution runs in O(nlogn) time and O(n) space.
Minimum Number of Removals to Make Mountain Array has been reported in interviews at Microsoft.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Minimum Number of Removals to Make Mountain Array is a Dynamic Programming (DP) Patterns problem, in the Longest Increasing Subsequence (LIS) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.