Problem · Array

Maximum Non-Adjacent House Value

MediumAmazonFULLTIMEONSITE INTERVIEW
See Amazon hiring insights

You are given an array values where values[i] is the amount available in the ith house arranged in a line.

You may choose any subset of houses, but you cannot choose two adjacent houses.

Return the maximum total value that can be collected.

Examples
01 · Example 1
values = [6,7,1,3,8,2,4]
return = 19

Choose houses with values 7, 8, and 4 for a total of 19.

Constraints
  • values contains the amount available in each house, with houses arranged in a line.
  • values has at least one element.
  • Each values[i] is a non-negative integer.
  • You cannot choose two adjacent houses.
More Amazon problems
drafts saved locally
public int maxNonAdjacentHouseValue(int[] values) {
  // write your code here
}
values[6,7,1,3,8,2,4]
expected19
checking account