DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
DP

House Robber

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **House Robber** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** dp[i] = max(dp[i-1], dp[i-2] + nums[i]) **Edge Cases to Consider:** - (1) Single house - (2) Two houses - (3) All same values

Examples

Example 1
Input: [1,2,3,1]
Output: 4
Explanation: Rob 1+3=4
Example 2
Input: [2,7,9,3,1]
Output: 12
Explanation: Rob 2+9+1=12
Example 3
Input: [1]
Output: 1
Explanation: Single house

Constraints

  • ▪Input arguments are within valid ranges
  • ▪Optimize for execution speed
  • ▪Handle null/empty inputs gracefully

Watch Out For Edge Cases

  • ▪Single house
  • ▪Two houses
  • ▪All same values
Frequently Asked At
AmazonGoogleMicrosoftMetaAdobeInfosys