← Discussions on Maximum Subarray
S shrutisha8
02 Sep 2026, 05:28

Simple approach explained for beginners.

A single pass with a running value is enough here. Keep track of the best answer so far and update it as you scan, which gives O(n) time and O(1) extra space.

1 reply

sneha_41 1 month, 2 weeks ago

Great explanation, the edge case with an empty input tripped me up too.

Sign in to reply.