The TransCompilator

Solved LeetCode program · 685 of 1,000

#0918 · Maximum Sum Circular Subarray

Medium Array chunk-14.md

Original English source

The numbers is a list of 1, -2, 3, and -2. The best is item 0 of numbers. The worst is item 0 of numbers. The ceiling is 0, while the floor is 0. The total is 0.
For every spot from 0 to the last position of numbers.
The value is item spot of numbers. Set ceiling to the larger of ceiling plus value and value. Set floor to the smaller of floor plus value and value. Set best to the larger of best and ceiling. Set worst to the smaller of worst and floor. Add value to total.

If best is less than 0, show best.
If best is at least 0.
The wrapped is total minus worst. The answer is the larger of best and wrapped. Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

3