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
valuescontains the amount available in each house, with houses arranged in a line.valueshas at least one element.- Each
values[i]is a non-negative integer. - You cannot choose two adjacent houses.
More Amazon problems
- Maximum System Memory CapacityOA · Seen Jul 2026
- Minimize Effort with EffiBin KitSeen Jul 2026
- Minimum Merge ConflictsOA · Seen Jul 2026
- Currency Conversion RatePHONE SCREEN · Seen Jul 2026
- Number of Islands IIONSITE INTERVIEW · Seen Jul 2026
- Minimum Operations to Make the Integer ZeroSeen Jul 2026
- Create Array Generator ServiceSeen Jul 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jul 2026
public int maxNonAdjacentHouseValue(int[] values) {
// write your code here
}values[6,7,1,3,8,2,4]
expected19
checking account