GrandTemple constraint doubt

what I will take the maximum size of the plot of kings land, as given in sample input and output 5 is considered the length and breadth of land so according to that max area is 2, so shall I consider the maximum value of input co-ordinate to be the length and breadth of land?
And is binarySearch applicable here or it’s a brute force question as I am unable to think about any particular sorting algorithm in this question

@Divya_321 No, you don’t have to use binary search, in this question you have to find the maximum length and maximum breadth on which river is not flowing.
Lets take the example of the given question. The x co-ordinates are {1,2,5} and the y co-ordinates are {1,4,2}. Since the river is flowing till infinite through the given points, it is safe to write the given co-ordinates in sorted order. So, x = {1,2,5} and y = {1,2,4}.
Now we have to find the largest length and largest breadth because they will give the largest area.
For length, we will subtract consecutive elements of y. As (4-2) > (2-1), our largest_length = (4-2-1), we are subtracting 1 from the result because river is flowing through the 4th co-ordinate as well and we can’t count that. Therefore, largest_length = 4-2-1 = 1.
For breadth, we will similarly subtract the consecutive elements of x. Since (5-2) > (2-1), our largest_breadth will be (5-2-1), reducing 1 for the similar reasons as of the largest_length, therefore, largest_breadth = 2.
Now that we have the largest_length and largest_breadth, we can easily find out the area for the grand temple.
Hence, the area = largest_length*largest_breadth = 1*2 = 2.
Hope this helps.

Thanks your explanation is really nice but what about the size of field and it’s dimesion what should I assume it ,and what if rivers don’t flow infinitely, and from where did I get this hypothesis that river is flowing infinitely.

And what if coordinates of river flowing for x are {1,4,5,8} and y are {4,5,8,9} according to your approach the ans is coming to be 4 but in actual it is 6

You only have to find the maximum area in between the given co-ordinates, so the dimensions of the field won’t matter. Also, you have to work with the assumption that the rivers will flow infinitely through the given co-ordinates.

No, the answer would be 4 square units only, 6 would be the wrong answer.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.