Data Structures & Algorithms using JavaScript Course
Data Structures & Algorithms using JavaScript
/
Advanced

Kadane's Algorithm

Definition

An elegant O(N) Dynamic Programming algorithm to find the maximum sum of a contiguous subarray. At each step, it calculates `currentMax = Math.max(nums[i], currentMax + nums[i])`.

Explain Like I'm New

At every step, you ask: 'Should I add this number to my existing streak, or is my streak so bad that I should just start a brand new streak right here?'

Interactive Coding Challenges

Kadane's Algorithm (Max Subarray Sum)

Solution Code

Loading...
Console output will appear here...
O(N) Time, O(1) Space.