HARDasked at 1 company

Make Array Non-decreasing or Non-increasing

A hard-tier problem at 65% community acceptance, tagged with Dynamic Programming, Greedy. Reported in interviews at VMware and 0 others.

Founder's read

Make Array Non-decreasing or Non-increasing is a hard DP problem that VMware has asked. The acceptance rate sits around 65 percent, which tells you it's solvable without cutting-edge technique, but most candidates who walk in unprepared will get stuck on the state definition. You're given an array and can replace elements with smaller values from a sorted list. The goal is to make the array either entirely non-decreasing or entirely non-increasing by minimizing the number of changes. If you hit this on an OA and blank on how to transition between states, StealthCoder solves it in seconds while you stay invisible to the proctor.

Companies asking
1
Difficulty
HARD
Acceptance
65%

Companies that ask "Make Array Non-decreasing or Non-increasing"

If this hits your live OA

Make Array Non-decreasing or Non-increasing 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. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.

Get StealthCoder
What this means

The trap is thinking you can solve this greedily or with a single pass. You can't. You need two separate DP passes, one for non-decreasing and one for non-increasing, then return the minimum cost. The real work is state definition: for each position, track the minimum operations needed to reach a valid configuration where the current element is replaced or kept, and all previous elements form a valid sequence. The greedy instinct fails because a cheap choice now (keeping a large value) blocks optimal choices later (forcing more changes downstream). This is where most candidates derail in a live setting. You need to build a DP table that tracks the cost of replacing element i with a value from the allowed set, then reference the cost of the best previous state. StealthCoder handles the indexing and state transitions so you don't have to reason through it under pressure.

Pattern tags

The honest play

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

Make Array Non-decreasing or Non-increasing 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. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Make Array Non-decreasing or Non-increasing interview FAQ

Is this really a problem a top company asks, or is it rare?+

VMware has confirmed asking it. With a 65 percent acceptance rate, it's not a rarified algorithm problem. It's hard because the state definition is non-obvious, not because it requires obscure technique. Most people who prepare on DP transitions will pass.

Can you solve it with a single pass?+

No. You need two full DP passes, one for non-decreasing and one for non-increasing. Each pass builds a cost table. Only after both completes do you compare and return the minimum. Single-pass greedy always fails on this problem.

What's the key trick I'm missing?+

Allowing element replacement from a sorted cost list, not arbitrary values. You iterate over allowed replacements for each position and track the minimum cost to transition from valid previous states. State is (position, last chosen value, non-decreasing or non-increasing flag).

How does this relate to Dynamic Programming and Greedy?+

Greedy fails because local choices block global optimality. DP solves it by exploring all valid transitions. The 'greedy' label hints that some people try to pick the cheapest replacement at each step, which doesn't work. Real solution uses DP state transitions.

If I see this on an OA, how much time should I allocate?+

Build and test the non-decreasing DP logic first, about 20 to 25 minutes. Copy and flip the logic for non-increasing. Debug for the remaining time. If you're stuck after 15 minutes, you're likely on a wrong approach and StealthCoder is your safety net.

Want the actual problem statement? View "Make Array Non-decreasing or Non-increasing" 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.