how output is coming 2 for sample input.
Grand temple.Unable to understand problem
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.