Algorithms

Maximum Subarray Sum

mediumalgorithmsdpkadanearray
0:00

Problem

Given an integer array `nums`, return the largest sum of any contiguous subarray. (Kadane's algorithm.)

Your solution
Test results
Click Run tests to check your solution against the test cases.

About this challenge

Maximum Subarray Sum is a medium algorithms coding challenge. It tests algorithmic thinking and complexity analysis — the kind of problem-solving that shows up constantly in technical interviews. Write your solution in the editor above, run it against the test cases, and get instant feedback — free, in your browser, no sign-up.

Show a hint & approach (spoiler)

Hint: Keep a running sum. If it ever goes negative, reset it to the current element. Track the max seen.

Keep practicing

Browse all coding challenges, or build intuition for the underlying concepts with the algorithm visualizers and the developer cheatsheets.