This is an interview question: given a boolean matrix find the size of the largest contiguous square sub-matrix, which contains only "true" elements.
I found this question on SO but did not understand the answer. The proposed algorithm moves a diagonal line from the left top to the right bottom and keeps track of the rectangles of "true" elements as the line goes.
My questions:
- How to keep track of the rectangles in the algorithm?
- Why do we move the diagonal line? What if we move a vertical/horizontal line or both?
- How to calculate the algorithm complexity?