m
as the number of rows and n
as the number of columns in the matrix.ans
to 0 to keep track of the maximum area found.row
from 0 to m
:
a. If row
is greater than 0, iterate over each column col
from 0 to n
:
i. If matrix[row][col]
is not 0, add matrix[row - 1][col]
to matrix[row][col]
.
b. Copy matrix[row]
to currRow
and sort currRow
in descending order.
c. Iterate over currRow
with index i
:
i. Calculate the area as currRow[i] * (i + 1)
.
ii. Update ans
with the maximum of ans
and the calculated area.ans
.