Reported September 2026
Walmartdynamic programming

House Robber

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

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

The edge case that kills a naive House Robber solution is the one nobody tests: a street with one house, or a greedy pick that grabs the biggest number and strands a better pair. Walmart reported this one in September 2026, and it's a clean dynamic programming problem with a tiny state. Pick non-adjacent houses, maximize the total, up to 10^5 houses. If you know the recurrence, it's five minutes. If you blank, StealthCoder runs invisibly during the live OA and gives you the solution as a safety net. Here's the script.

The problem

You are given an integer array nums. The value nums[i] is the amount available in the ith house on a street.
You may choose any set of houses, but you cannot choose two adjacent houses.
Return the maximum total amount you can collect.

Function
rob(nums: int[]) → int

Examples
Example 1
nums = [2,5,1,3]
return = 8
Choose the houses with amounts 5 and 3. They are not adjacent, and their total is 8.
Example 2
nums = [4,1,1,9,1]
return = 13
Choose the first house with amount 4 and the fourth house with amount 9 for a total of 13.

Constraints
1 <= nums.length <= 10^5
0 <= nums[i] <= 10^4
The maximum total fits in a signed int.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a two-variable DP. At each house you either skip it (keep the best so far) or take it (add its value to the best from two houses back). So best[i] = max(best[i-1], best[i-2] + nums[i]). You only need the last two values, so space is O(1) and time is O(n). Check example 2: [4,1,1,9,1] gives 13 by taking 4 and 9. The pitfall is greedy. Picking the largest value first or alternating indices fails on inputs like [2,5,1,3] versus [4,1,1,9,1]. The second pitfall is the edge case. Length 1 must return nums[0], and your loop shouldn't index nums[1] blindly. Zeros are allowed, so don't assume values are positive. If your mind goes empty mid-assessment, StealthCoder is the hedge on the live OA. It reads the prompt and hands you the rolling-variable solution.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill House Robber 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 for the candidate who got the OA invite this morning and has 72 hours, not six months.

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 Walmart's OA.

Walmart reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

House Robber FAQ

How hard is House Robber really in the Walmart OA?+

It's an easy-to-medium DP problem. The recurrence is short and the code is under ten lines. The difficulty is spotting that greedy fails and that the decision at each house depends only on the previous two results.

What's the trick to solving it fast?+

Track two values: the best total up to the previous house and the best up to the house before that. At each house, new best is max(prev, prevPrev + current). Shift the variables forward. No array needed, one pass.

Why does greedy fail here?+

Taking the largest house first can block two better neighbors. In [2,5,1,3], the answer 8 uses 5 and 3. Local choices don't see that skipping a house now can open a bigger pair later. DP compares both options at every step.

What edge cases should I test?+

Test a single house, two houses (return the larger), and all zeros. Also test a long input near 10^5 to confirm O(n) runs fine. With one house, make sure you return nums[0] without reading an index that doesn't exist.

How do I prepare in 48 hours?+

Write the recurrence from memory, then code it with two variables. Run both examples by hand, 8 and 13. Then do the circular-street variant once so you recognize the twist. That covers most of what this pattern throws at you.

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

OA at Walmart?
Invisible during screen share
Get it