Possible Duplicate:
Find largest rectangle containing only zeros in an N×N binary matrix
Here is a n*m matrix filled up with 0s and 1s. I need to find the biggest rectangular made of 1s. The biggest rectangular made of 0s is equivalent as I can use 0 instead of 1. So in this example, 8x8 matrix: The biggest rectangular is the submatrix starting at (2,0) and diagonally ending at (7,1) having 12 1s.
10011110
10011110
11100010
11100010
11100000
11001111
11000000
11000000
This is not a HOMEWORK. This is one of my preparation questions for an interview.
I came up with the following solution. Start at (0,0) and for each element, try to go diagonally if possible, thereby check the other elements forming that particular rectangle in both directions (say the diagonal end is 2,2 I would check 2,1 and 1,2 for 1s), otherwise go left or right depending on the 1s that exist. If rectangular is expanded, mark the cell with the current number of 1s included in the rectangular.
How would you approach? What do you think of my solution?