Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

House Robber II

Medium
dynamic-programmingarray

Same as House Robber, but the houses form a circle — the first and last are adjacent. Return the maximum loot.

Input: one line of space-separated non-negative integers. Output: the maximum amount.

Example 1
Input:
2 3 2
Output:
3

Houses 0 and 2 are adjacent — can't take both 2s.

Example 2
Input:
1 2 3 1
Output:
4

Constraints

  • 1 ≤ nums.length ≤ 100
  • 0 ≤ nums[i] ≤ 1000
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.