BBlinkit·DSASDE-1DSA Phone Screen
Solve the House Robber II (circular arrangement) problem
Extension of House Robber I where houses form a circle, meaning the first and last house are adjacent and cannot both be robbed.
Approach: Break the circular constraint by running two separate linear DP passes — one excluding the first house, one excluding the last — and return the maximum of the two results. This reduces the problem to the classic linear House Robber.
- Time: O(n), Space: O(1) (track only prev two values)
- Edge cases: n=1 (return nums[0]), n=2 (return max of both)
Follow-ups: k-skip constraint (can't rob within k houses), 2D grid variant, or reconstructing which houses were robbed.
added 2 days ago