The Runtime Theory
mediumLeetCode#dynamic-programming#circular-array

House Robber II

Maximize nonadjacent values in a circle where first and last houses are neighbors.

The Runtime Theory Team25 min read
Solve it

Solving happens on the judge — come back and mark it done

Sample cases

innums=[2,3,2]

out3

innums=[1,2,3,1]

out4

innums=[1]

out1

Maximize nonadjacent values in a circle where first and last houses are neighbors.

A good solution should

  • State the invariant or decision rule that makes the approach correct.
  • Explain time and space costs in terms of input size and required output.
  • Handle empty, minimal, duplicate, and boundary-shaped inputs.

Reasoning prompt

Exclude either the first or last position and solve the remaining linear range; handle a single house separately.

Use the linked judge for the canonical challenge. The examples above are compact TRT checks; create additional tests around the boundary most likely to break your invariant.

More practice in this topic

One dispatch a week

The trace behind each problem, the tradeoff that explains it, and one technical dispatch per week — no noise.

One technical dispatch per week. No noise.

Not started

Sign in to save your learning progress.

Sign in to save