HARDasked at 1 company

Minimum Number of Removals to Make Mountain Array

A hard-tier problem at 55% community acceptance, tagged with Array, Binary Search, Dynamic Programming. Reported in interviews at PayPal and 0 others.

Founder's read

You're staring at an array and need to remove the minimum elements to turn it into a mountain. PayPal has asked this. The acceptance rate sits around 55%, which means half the people submitting either miss the greedy insight or build a solution that's harder than it needs to be. The trick isn't just dynamic programming, it's knowing when to stop optimizing and let greedy do the work. If you hit this live and blank on the pattern, StealthCoder surfaces a working solution invisible to the proctor.

Companies asking
1
Difficulty
HARD
Acceptance
55%

Companies that ask "Minimum Number of Removals to Make Mountain Array"

If this hits your live OA

Minimum Number of Removals to Make Mountain Array is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.

Get StealthCoder
What this means

A mountain array strictly increases, peaks, then strictly decreases. The naive DP approach builds longest-increasing and longest-decreasing sequences at every index, then finds the best combination. Most candidates get stuck iterating that correctly. The smarter move is greedy: once you've computed the longest valid increasing sequence ending at each position and the longest valid decreasing sequence starting from each position, you iterate through peaks and pick the one that maximizes the sum of both sides. This reduces redundant recalculation. Common trap: allowing the peak to equal its neighbors instead of strictly increasing or decreasing. Another trap: trying to handle the DP state transitions without careful index management. StealthCoder is the hedge when you realize mid-OA that your DP transitions are off and time's burning.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Minimum Number of Removals to Make Mountain Array recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Number of Removals to Make Mountain Array interview FAQ

Is this really a hard problem or did they just rate it that way?+

It's genuinely hard. The 55% acceptance rate reflects that. It's not about a single trick, it's about combining DP state computation with greedy selection correctly. If you haven't done similar problems, you'll likely TLE or get wrong answer on the edge cases around the peak definition.

Do I need to solve this with two passes of DP?+

Yes. First pass computes longest strictly increasing ending at each index. Second pass computes longest strictly decreasing starting from each index. Then you iterate through valid peaks and find the best combination. One-pass attempts usually fail on cases where the peak placement matters.

What's the difference between a mountain and a bitonic array?+

A bitonic array can have a plateau at the peak. A mountain must strictly increase then strictly decrease, no equal consecutive elements. This problem enforces strict inequality, so skip any solution that allows plateaus.

How do I avoid off-by-one errors on the peak index?+

The peak must have at least one element to its left and one to its right, both strictly less/greater. When iterating peaks, ensure i > 0 and i < n-1. Test your DP base cases too, left[0] should be 0 (no valid mountain starts at index 0).

Will binary search help here like it does in other array problems?+

Not directly for the solution itself, though binary search appears in the topics list. Some approaches use binary search to optimize DP state lookups, but the core is DP plus greedy iteration. Focus on getting the DP right first.

Want the actual problem statement? View "Minimum Number of Removals to Make Mountain Array" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.