House Robber (DP on a Line and a Circle)

medium
Unit 11 · Dynamic Programming I0/2 to milestone

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