FastPrepHouse Robber
Problems/House Robber

House Robber

Walmart logoWalmart● MediumFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report identifies this task and its central operation. This practice version states the deterministic interface, boundary behavior, and ordering rules needed for consistent execution while preserving the reported capability.

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.

More Walmart problems

  • Merge a List In Between Two PositionsONSITE INTERVIEW · Seen Nov 2026
  • Merge Intervals from Start and End ListsONSITE INTERVIEW · Seen Nov 2026
  • Palindrome Check Ignoring SymbolsONSITE INTERVIEW · Seen Nov 2026
All Walmart interview questionsSee Walmart hiring insights
Saved
class Solution {
    public int rob(int[] nums) {
        // write your code here
    }
}
Checking account…