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

Kadane’s Algorithm Explained with Examples

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

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

Solving smaller problems today to solve bigger problems tomorrow!

Learn More
LEARN MORE ABOUT @MITHRATALLURI'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Mithra Talluri HackerNoon profile picture
Mithra Talluri@mithratalluri
Solving smaller problems today to solve bigger problems tomorrow!

TOPICS

Languages

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