FunctionRacerProblemsRace

Best Stretch Around a Ring

MediumArraysPython, JavaScript, TypeScript, Java, C++

The items of nums sit around a ring: after the last item comes the first one again. A stretch is one or more items that sit next to each other on the ring, so it may run past the end of the list and continue at the start, but it never uses an item twice.

Return the largest sum a stretch can have.

Example 1

nums [4,-6,3]
returns 7

The stretch runs from the last item around to the first: 3 + 4.

Example 2

nums [-4,-1,-6]
returns -1

Every item is a loss, so the best stretch is the single item -1.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Arrays problems