House Robber
Mediumjavapythonccppjavascript
Given the money in each house along a street, find the maximum amount you can collect without robbing two adjacent houses.
Input Format
The first line contains an integer N. The second line contains N space-separated non-negative integers.
Output Format
Print the maximum amount that can be robbed.
Example 1
Input
5 2 7 9 3 1
Output
12
Explanation: Rob houses with 2, 9 and 1 for a total of 12.
- 1 <= N <= 100000
- 0 <= A[i] <= 1000000000
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- 0/1 KnapsackMedium · java, python, c, cpp, javascriptSolve Problem
- Longest Common SubsequenceMedium · java, python, c, cpp, javascriptSolve Problem
- Longest Increasing SubsequenceMedium · java, python, c, cpp, javascriptSolve Problem