House Robber (DP on a Line and a Circle)

medium
Checkpoint challenge
Solve this to show you know the material and jump straight to Unit 12. Everything before it counts as cleared.

Houses along a street hold values[i]. You can't take from two adjacent houses.

Implement:

  • rob(values): the maximum total, in O(n) time and O(1) memory.
  • rob_circle(values): the same, but the houses form a circle, so the first and last are adjacent.
  • rob_choice(values): the indices chosen for an optimal line solution, ascending. When there's a tie, prefer not taking the current house (scan from the end).
#dynamic-programming2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
House Robber (DP on a Line and a Circle) · TechGradify