Trains the technique from
LeetCode 918Maximum Sum Circular SubarrayThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A ring road is split into n tolled sections laid end to end around a circle and numbered 0 through n - 1, with section n - 1 running straight into section 0. ledger[i] is last quarter's net result for section i, in thousands, and it is negative on a section whose upkeep cost more than its tolls brought in.
An arc is a non-empty run of sections taken in ring order, so an arc is allowed to carry on past section n - 1 and continue at section 0. An arc may not visit a section twice, so it holds between 1 and n sections.
Return the largest net total any single arc reaches.
Example 1
The arc that begins at section 4 and carries on through sections 0, 1 and 2 totals 4 + 5 - 3 + 6 = 12.
Example 2
The arc holding section 2 and then section 0 totals 3 + 3 = 6.
Example 3
Section 1 on its own is an arc, and its total is -2.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def best_ring_arc(ledger: list[int]) -> int:public int bestRingArc(int[] ledger)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.