Example 1
Input
values = [1, 2, 3, 1]
Output
4
Loading CodeSprint...
/problems/house-robber
Each position contains the value stored in one house. Adjacent houses cannot both be selected. Return the greatest total obtainable without choosing neighboring positions.
Implement this function and return the result. CodeSprint supplies each test case automatically.
rob(values) → numberInput
values = [1, 2, 3, 1]
Output
4
Input
values = [2, 7, 9, 3, 1]
Output
12
Constraints
0 <= values.length <= 100,000 0 <= values[i] <= 100,000