Given two rectangles, of size M * N and X * Y respectively. We need to find biggest square common among those that can be obtained by deleting some rows and columns of given rectangle. Its like finding common sequence in 2D. I know how to do it in 1 dimensional but how it can be modified for this problem.
Example :
Let first rectangle is of 3 * 4
1 2 0 5
1 2 1 6
1 2 3 7
Let second rectangle is 3 * 3
0 1 2
1 1 2
3 1 2
So here size of biggest common sub square is 2.
We can assume that 1 ≤ N, M, X, Y ≤ 700 and all numbers in both rectangles are integers in the interval [1, 1000].
I am looking for something O(N^3) solution. My current approach for this is try for every square in first grid, and try to fit it in second grid. It is very time consuming because for every subsquare you are using O(N^3) And then for looking weather its present in second one we need O(N^2).