There is a problem to find the maximum area of the 1 in the 0-1 matrix. In this problem there are two cases:
area to be measure is of shape square. that\'s
I would try the following:
(1) Decompose the matrix into connected components (through BFS).
(2) For each connected component, look for the maximal rectangle.
To do (2), I would first look for vertical rectangles: Find the maximal possible width for each consecutive (min_y, max_y), and therefore the area (iteratively, in O(1) per row, just by looking at the min/max of 1's in that row of the connected component). Then I would transpose the matrix, and repeat the process.
The total running time is O(MxN) for BFS, then O(width^2 + height^2) for each connected componenet, for a total of O(MXN + M^2 + N^2).
I wonder what's the asymptotically optimal solution though.