Best Stretch Around a Ring
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
1 <= len(nums) <= 100-1000 <= nums[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Arrays problems
- Fewest Swaps to SortMedium
- Insert IntervalMedium
- Longest HillMedium
- Maximum SubarrayMedium
- Next PermutationMedium
- Nudge Every ItemMedium
- Product of Array Except SelfMedium
- Range IncrementsMedium