SSpanKestrel
Workflows

Coding workflows · Maximum contiguous sum

03
Built around your work

A concrete starting point

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.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Maximum contiguous sum

A concrete starting point
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 best

The 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.

AI coding workspace

Your next change starts here.

Get the Windows app ↗