Skip to content

Kadane's algorithm can find the maximum sum rectangle in a 2D array by iterating over column pairs, computing row sums for each pair, and applying Kadane's algorithm to these sums. This identifies the maximum sum rectangle in the 2D array.

Notifications You must be signed in to change notification settings

DevaRajan8/Maximum-sum-rectangle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Kadane's algorithm, originally designed for finding the maximum sum subarray in a 1D array, can be extended to solve the maximum sum rectangle problem in a 2D array or matrix. The idea is to fix the left and right columns one by one and find the maximum sum subarray between them for all pairs of rows. This is essentially applying Kadane's algorithm on the columns within the fixed left and right boundaries.

To implement the algorithm, iterate over all possible pairs of columns and maintain an array representing the cumulative sum of elements in each row between those columns. Apply Kadane's algorithm on this 1D array of row sums, which will give the maximum sum subarray in that range of rows. By iterating through all pairs of columns and applying Kadane's algorithm, the algorithm identifies the rectangle with the maximum sum in the 2D array.

This algorithm has a time complexity of O(n^3), where 'n' is the number

About

Kadane's algorithm can find the maximum sum rectangle in a 2D array by iterating over column pairs, computing row sums for each pair, and applying Kadane's algorithm to these sums. This identifies the maximum sum rectangle in the 2D array.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages