InferenceAI

Enter at least two characters to search.

Start free

Circular Street Robbery

mediumDynamic Programming25 min25 XP

Houses are arranged in a circle with values nums. You can't take two adjacent houses, and the first and last are adjacent. Return the maximum total.

Examples

EXAMPLE WALKTHROUGHthree houses

A guided view of the published example, not a trace of your code.

INPUT[[2,3,2]]
TASKcircular_street_robbery()
EXPECTED OUTPUT3

Start with the input values shown in this example.

Example 1 of 3

Input: nums = [2,3,2]

Output: 3

Explanation: three houses

Input: nums = [1,2,3,1]

Output: 4

Explanation: four houses

Input: nums = [5]

Output: 5

Explanation: single house

Hint 1

Solve the straight-line problem twice: once without the first house and once without the last.

Topics

DSADynamic ProgrammingPython