FastPrepHouse Robber
Problems/House Robber

House Robber

Amazon logoAmazon● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported task identifies this standard algorithmic exercise. The executable interface, bounds, deterministic tie rules, and examples are the documented practice contract.

You are given an array nums, where nums[i] is the amount of money in house i.

Adjacent houses cannot both be robbed. Return the maximum total amount that can be robbed without choosing two adjacent houses.

Function

rob(nums: int[]) → int

Examples

Example 1

nums = [1,2,3,1]return = 4

Rob houses 0 and 2 for 1 + 3 = 4.

Example 2

nums = [2,7,9,3,1]return = 12

Rob houses 0, 2, and 4 for 2 + 9 + 1 = 12.

Example 3

nums = [5]return = 5

The only house can be robbed.

Constraints

  • 1 <= nums.length <= 100.
  • 0 <= nums[i] <= 400.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public int rob(int[] nums) {
        // Write your code here.
    }

}
Checking account…