Maximum circular subarray
Return the maximum nonempty contiguous sum in a circular integer list. Input is nonempty and no item may be used more than once.
items = [5, -3, 5]
minimum_subarray = -3
print(sum(items)-minimum_subarray)Reason about the state
A wrapped answer equals total minus the minimum nonempty subarray. Handle all-negative input separately so the complement does not select an empty subarray. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return the maximum nonempty contiguous sum in a circular integer list. Input is nonempty and no item may be used more than once.
The explanation opens here once every check passes.