LC 53
LeetCode 53 · Medium

Maximum Subarray

Find the contiguous subarray with the largest sum.

Greedy → · Very high frequency · Solve on LeetCode →

Try it

Step through the core mechanic. The simulator below runs the greedy shape this problem is built on.

Walk the pattern

No dedicated step-through for this one yet. The shape is Greedy — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.

The approach

Kadane: the best sum ending here is max(nums[i], bestEndingHere + nums[i]) — extend the run or restart at i. Track the global best as you sweep.

AspectValue
PatternGreedy
Recognise it byLargest contiguous sum — Kadane.
Time complexityO(n)
Space complexityO(1)
DifficultyMedium

Who asks it

Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.