Tap here to switch tabs
Problem
Ask
Submissions
Solution

Solution: House Robber II

Statement

Naive approach

The rule to decide about robbing a particular house is to either rob the current house and skip the adjacent house or skip the current house and rob the adjacent house. The house containing the greater amount will get selected from these two options. For the given set of houses, we must accumulate the robbed amount for all houses according to the rule mentioned above. This requires exhaustive testing of all possible combinations and selecting a combination that gives the maximum robbery amount.

We will have repeated subcombinations to traverse in multiple computations. Also, while robbing, we cannot allow the first and last houses to be robbed in a single combination because they are neighbors. So, we will divide the houses into two sets, ranging from 11 ...

Tap here to switch tabs
Problem
Ask
Submissions
Solution

Solution: House Robber II

Statement

Naive approach

The rule to decide about robbing a particular house is to either rob the current house and skip the adjacent house or skip the current house and rob the adjacent house. The house containing the greater amount will get selected from these two options. For the given set of houses, we must accumulate the robbed amount for all houses according to the rule mentioned above. This requires exhaustive testing of all possible combinations and selecting a combination that gives the maximum robbery amount.

We will have repeated subcombinations to traverse in multiple computations. Also, while robbing, we cannot allow the first and last houses to be robbed in a single combination because they are neighbors. So, we will divide the houses into two sets, ranging from 11 ...