House Robber

A street has houses in a row, and houses[i] is how much money house i holds. You may collect from any houses you like, but never from two that are next to each other. Return the most money you can collect.

Constraints

  • 1 ≤ length of houses ≤ 10,000
  • 0 ≤ houses[i] ≤ 10,000

Example 1

Input
houses = [1,2,3,1]
Output
4
Why:

Houses 0 and 2: 1 + 3.

Example 2

Input
houses = [2,7,9,3,1]
Output
12
Why:

Houses 0, 2 and 4: 2 + 9 + 1.

Hints

    Was this a good challenge?

    Solved by
    0
    Submissions
    0
    Accepted
    –