Open the context
Choose the project folder and name the files or behavior involved.
Find the greatest contiguous sum in at most 1000 integers bounded by one billion in magnitude, returning sum and exclusive bounds. Test all-negative and empty input, resolving ties by earliest start then earliest end.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def maximum_subarray(values):
if type(values) not in (list, tuple) or len(values) > 1000 or any(type(v) is not int or abs(v) > 10**9 for v in values):
raise ValueError("subarray.input")
if not values:
return None
best = None
total, start = 0, 0
for end, value in enumerate(values, 1):
if total < 0:
total, start = 0, end - 1
total += value
candidate = (total, start, end)
if best is None or (-total, start, end) < (-best[0], best[1], best[2]):
best = candidate
return bestThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.