FastPrepHouse Robber
Problems/House Robber

House Robber

Visa logoVisa● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: In the first technical interview, after questions about the candidate's resume, there was time left for one coding question. The candidate said it was similar to House Robber and talked through a brute-force idea and a faster one.

The report does not say how the question differed from House Robber. Here you get the standard version: houses in a row, no two neighbors, and the largest total. Limits are added so that the fast solution matters.

The judged task matches the report at about 70%.

Houses stand in a row along a street. nums[i] is the amount of money in house i.

You may take the money from any houses you like, but you can never take from two houses that are next to each other. Houses i and i + 1 are next to each other. The street does not wrap around, so the first and last houses are not neighbors unless there are only two houses.

Return the largest total amount of money you can take.

Function

rob(nums: int[]) → int

Examples

Example 1

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

Take houses 0 and 2 for 1 + 3 = 4. Taking houses 1 and 3 gives only 2 + 1 = 3.

Example 2

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

Take houses 0, 2, and 4 for 2 + 9 + 1 = 12. No two of them are next to each other.

Example 3

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

Take houses 0 and 3 for 2 + 2 = 4. The best choice does not have to be every other house: houses 0 and 2 give only 3.

Constraints

  • 1 <= nums.length <= 10^4
  • 0 <= nums[i] <= 10^4

More Visa problems

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • House Robber IIIPHONE SCREEN · Seen Nov 2026
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int rob(int[] nums) {
        // Write your code here.
    }
}
Checking account…