Samsung Competency Test 25 Aug 19

There is a large plot with various sinkholes present. Since one sinkhole can combine with another sinkhole, it is required to get at most one sinkhole while occupying the plot. You have to find the maximum square-area formed with at least one sinkhole present. If there are two plots with the same area then print the one with lesser sinkhole present otherwise if the sinkholes are also same then print anyone. For each case, you have to print the bottom leftmost coordinate and top rightmost point. Please keep in mind that the plot starts with (1, 1).

Time limit= 1sec and Memory limit– 256Mb

Input: First line will give the number of test cases. For each test case, we will be given the size of the plot matrix N x M (where 1<=N, M<=1000). Next line will give the number of sinkholes present in the matrix K (1<=K<=N+M). Next, K-lines will give the coordinates of the sinkholes.



Output: For each test case, you have to print the number of the test case and the coordinates of the resultant square. i.e. #i xb yb xt yt (ith test case, xb=bottomost left x-coordinate, yb=bottomost  left y-coordinate, xt= topmost right x-coordinate, yt= topmost right y-coordinate)

Example:

i/p:

1

6 6

4

1 1

3 3

4 4

6 6



Matrix Formed will look something like this-

0 0 0 0 0 1

0 0 0 0 0 0

0 0 0 1 0 0

0 0 1 0 0 0

0 0 0 0 0 0

1 0 0 0 0 0

 

o/p:

#1 1 4 3 6

 

Verdict: I solved using brute-force with O(n^4) and got TLE. So was not selected. I am not sure but any approach with O(n^3) should work !!

Write your Interview Experience or mail it to contribute@geeksforgeeks.org




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.