Reported September 2026
Amazondynamic programming

Maximum Non-Adjacent House Value

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

The Amazon OA reported in September 2026 looks like a gentle warm-up, and that's the trap. Maximum Non-Adjacent House Value is the classic house robber setup, and the naive greedy approach of grabbing the biggest value and skipping its neighbors quietly fails. A single-element array and a two-element array also trip people who hardcode the loop start. If you've got this invite, the pattern is dynamic programming, and it's about ten lines once you see it. StealthCoder sits as a safety net on the live OA if your mind goes blank mid-problem, but the idea here is small enough to carry in your head.

The problem

You are given an array values where values[i] is the amount available in the ith house arranged in a line.
You may choose any subset of houses, but you cannot choose two adjacent houses.
Return the maximum total value that can be collected.

Function
maxNonAdjacentHouseValue(values: int[]) → int

Examples
Example 1
values = [6,7,1,3,8,2,4]
return = 19
Choose houses with values 7, 8, and 4 for a total of 19.

Constraints
values contains the amount available in each house, with houses arranged in a line.
values has at least one element.
Each values[i] is a non-negative integer.
You cannot choose two adjacent houses.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a two-state recurrence. At each house you either skip it and keep the best so far, or take it and add the best from two houses back. So best[i] = max(best[i-1], best[i-2] + values[i]). You only need two variables, so space is O(1) and time is O(n). Check it against the example [6,7,1,3,8,2,4]: the answer is 19 from 7, 8 and 4. A greedy pick of 8 first, then 6 and 4, only gets 18, which is why greedy fails. The pitfalls are edge cases. One element means return that element. Two elements means return the max of the two. Values are non-negative, so zeros are fine and you don't need negative handling. If you freeze on the live OA, StealthCoder can hand you the recurrence, but you should still trace the example by hand to verify it.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Maximum Non-Adjacent House Value cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as house robber. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Non-Adjacent House Value FAQ

What's the trick to Maximum Non-Adjacent House Value?+

Use a rolling two-variable DP. For each value, compute the new best as the max of the previous best (skip this house) and the best from two steps back plus the current value (take it). Update the two variables each step and return the last best.

Why does greedy fail on this problem?+

Picking the largest value first can block two good neighbors. In [6,7,1,3,8,2,4], grabbing 8 then 6 and 4 gives 18, but 7, 8 and 4 gives 19. Locally best choices don't guarantee the global best, so you need DP.

What edge cases should I test for the Amazon OA version?+

Test a single-element array, a two-element array, all zeros, and arrays where the best answer skips two houses in a row. Values are non-negative and there's at least one element, so you don't need to handle an empty array or negatives.

What's the time and space complexity I should aim for?+

O(n) time with one pass and O(1) space using two rolling variables. A full DP array also works and is fine to submit, but the constant-space version shows you understand that each state only depends on the previous two.

How do I prepare for this in 48 hours?+

Write the recurrence from memory twice, then trace it on the sample by hand. Practice the one and two element cases so your loop start is right. This is a very common DP shape, so nail it and move on to variants like the circular house arrangement.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it