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
  • 1 <= values.length <= 2 * 10^5
  • 0 <= values[i] <= 10^9
More Amazon problems
drafts saved locally
public int maxNonAdjacentHouseValue(int[] values) {
  // write your code here
}
values[6,7,1,3,8,2,4]
expected19
sign in to submit