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^50 <= values[i] <= 10^9
More Amazon problems
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Running Delivery Time MediansONSITE INTERVIEW · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
public int maxNonAdjacentHouseValue(int[] values) {
// write your code here
}values[6,7,1,3,8,2,4]
expected19
sign in to submit