paint-brush
Kadane’s Algorithm Explained with Examplesby@mithratalluri
57,587 reads
57,587 reads

Kadane’s Algorithm Explained with Examples

by Mithra TalluriDecember 13th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Given an array, the algorithm to find the maximum subarray sum is called Kadane’s Algorithm. It can be applied to a 1D array or 2D matrix. The algorithm can be of any dimension. We could optimize the space complexity by taking dp[i-1] which is the previous sum into a variable, eliminating the need for dp[] array. We have two choices: either start at the current index or add the current element to the maximum of 0 and previous sum.
featured image - Kadane’s Algorithm Explained with Examples
Mithra Talluri HackerNoon profile picture
Mithra Talluri

Mithra Talluri

@mithratalluri

L O A D I N G
. . . comments & more!

About Author

Mithra Talluri HackerNoon profile picture
Mithra Talluri@mithratalluri

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite