Help i cant understand the problem

please explain me the problem how the test case answer is 2

@anupanu23
You have to maximise the area obtained between the rivers. Since the intersection points of rivers are provided to you as input , you need to find the largest consecutive gap between the x coordinates and y coordinates.

This problem falls under the Greedy Algorithms section. A very similar problem ( practically the same ) is covered in the Greedy Algorithms tutorial video as well.
You need to implement a greedy algorithm for this problem.
Take the x coordinates input in an array , say X .
Take the y coordinates input in an array , say Y .
We need to find the maximum area. We can obtain it by finding the largest gap in the x coordinates and multiplying with the largest gap in the y coordinates.
So just do that , find the maximum gap between consecutive x coordinates in the X array and do the same for Y.
Multiply these maximum gaps and you will have your maximum area.
Hint : Sorting might help.

For the given testcase , the maximum area will be obtained by the rectangle whose corner points are (2,2) , (2,4) , (5,2) , (5,4) . There will be 2 square units left in this rectangle and that is the answer for the given testcase. Kindly try plotting these points on paper and you will understand how this works.

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.