Difficulty: Medium | Category: Dynamic Programming | Asked at: Google, Meta, Amazon | Platform: Unfoldd Arena
Solve House Robber online for free in Python, JavaScript, Java, C++, TypeScript, Go, Rust, PHP, Swift, Kotlin, Dart, Ruby, C, and C#. Practice Medium level coding interview problems with instant test case evaluation and AI-powered analysis.
Keywords: House Robber solution, House Robber leetcode, House Robber python, House Robber javascript,House Robber java, House Robber approach, how to solve House Robber, medium coding problems, Dynamic Programming problems, coding interview preparation, DSA practice free.
You are a burglar who breaks into houses and steals money. However, you are not a common burglar, but rather a burglar who recognizes the "Catch 22" situation when there are guards. If there is a guard on the roof of a house (which you can't see from the street), you won't be able to jump onto the roof (and this would be considered poor planning, not a reaction to an input on the street). However, if there isn't an alarm system at that house, then you can jump onto its roof.
You can either rob the houses on the same street or you can steal from the houses which are not on the same street but on the same side. You cannot rob a house with any alarm system installed since it would attract the police immediately. The police would arrive before you reach the next house even if you are running extremely fast. Also, you cannot rob a house and then jump onto the roof of the adjacent house without robbing the house. However you can jump onto a house with an alarm system if you do it immediately from a previously robbed house.
You are given a list of houses and their respective alarm status on the street. Each house can have one of three conditions. It can be either a house with an alarm system, or a house without an alarm system, or an empty house. The objective is to determine the maximum total amount of money that can be robbed from houses on the street.
nALARMNO_ALARMEMPTYALARMNO_ALARMEMPTYPlease note that the rules mentioned may need to be relaxed depending on the actual requirements of the problem. However in this problem we are considering the most restrictive scenario where you cannot rob two adjacent houses without an alarm system installed, and at a house with an alarm system, or at an adjacent house if the house adjacent to it has an alarm system.
Input: {"input_data":[1,2,3]} Output: [1,2,3]
Solve problems, verify your skills, and earn XP.