House Robber
Medium Acceptance 51.45% Points 30.00
You are given an integer array nums representing the amount of money in each house along a street. You cannot rob two adjacent houses.
Your task is to return the maximum amount of money you can rob without alerting the police.
Examples
Example 1
Input: nums = [1,2,3,1]
Output: 4
Explanation: Rob house 0 (1) and house 2 (3) for a total of 4.
Example 2
Input: nums = [2,7,9,3,1]
Output: 12
Explanation: Rob houses 0, 2, and 4 for a total of 2 + 9 + 1 = 12.
Example 3
Input: nums = [5]
Output: 5
Explanation: With only one house, rob it for a total of 5.
Hints
Hint 1
- Hint 1: At each house, you have a choice between taking its money or skipping it.
Hint 2
- Hint 2: Think about how the best result up to the current house depends on earlier houses.
Hint 3
- Hint 3: Try keeping only the small amount of information needed to make the next decision.
Companies
Apple Morgan Stanly
Topics
Dynamic Programming
Track your submissions
Please log in to review your progress and explore code submissions from other participants.
Unlock the full solution
Please log in to access detailed answers and explanations.
Join the discussion
Please log in to join conversations with other participants.