FastPrepMost Cash From Non-Neighboring Houses
Problems/Most Cash From Non-Neighboring Houses

Most Cash From Non-Neighboring Houses

Adobe logoAdobe● MediumFULLTIMEINTERNPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: Three Adobe first-round reports name this classic task: pick houses in a row to collect the most money, never two neighbors. In one, after moving from plain recursion to memoization, the candidate walked the interviewer through test inputs and the values in the DP table. In another, pseudo-code was enough, and the version with the houses in a circle came up too. The third gives only the name.

None of the reports gives limits or examples. Here there are 1 to 400 houses with 0 to 1000 each, and the examples are our own. The dry run and the circle version are covered in the editorial and are not judged.

The judged task matches the reports at about 95%.

Houses stand in a row. money[i] is the amount of cash in house i.

You may collect the cash from any set of houses, with one rule: you can never take from two houses that are next to each other. Return the largest total you can collect.

Function

maxLoot(money: int[]) → int

Examples

Example 1

money = [3,10,3,1,2]return = 12

Take the houses at index 1 (10) and index 4 (2). They are not next to each other, and the total is 12. No other choice does better. For example, indexes 0, 2 and 4 give 3 + 3 + 2 = 8, and indexes 1 and 3 give 10 + 1 = 11.

Example 2

money = [6,1,1,6]return = 12

Take the first and the last house: 6 + 6 = 12. Skipping two houses in a row is allowed, and here it pays off. Taking every other house gives only 6 + 1 = 7 or 1 + 6 = 7.

Example 3

money = [5]return = 5

There is only one house, so take it.

Constraints

  • 1 <= money.length <= 400
  • 0 <= money[i] <= 1000

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public int maxLoot(int[] money) {
    // Write your code here.
}
Checking account…