An odd fellow recently became the mayor of the city. He wants to build a large rectangular carrot farm.
However, a large number of points in the city are already occupied with annoying stuff like apartments, clubs, and shopping malls. We need to find the largest contiguous rectangular plot in the city which is empty.
Assuming the entire city to be of blocks, numbered from 0 to 999 in both dimensions, these are the coordinates of the obstacles. What is the area of the largest carrot farm that can be built, i.e, the largest empty submatrix?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
I've used Divide and Conquer approach.
Key Idea
Divide the matrix into two halves left and right, and now biggest rectangle occurring in the matrix is one of the following:
The biggest rectangle completely residing in left matrix
The biggest rectangle completely residing in right matrix
The biggest rectangle residing partially in left and partially in right matrix
Run Time Analysis
Its O ( n 2 ) because the algorithm follows T ( n ) = 4 ⋅ T [ 4 n ] + O ( n 2 ) , where T ( n ) is the number of steps for matrix of size n × n .