In the sample case given for this question, i think the output is wrong because the largest temple can be build of size 6 units enclosed by points (2,1), (5,1), (5,4) and (2,4).
https://ide.codingblocks.com/s/162780 this is the link to my code.
Grand Temple Question
@Kajal For the sample test case:
3
1 1
2 4
5 2
Expected Output:
2
Output should not be 6.
All we need to do is just store all the X and Y coordinates and then sort them. Then we will calculate maximum ΔX and ΔY where ΔX = (Xi -Xi-1) & ΔY = (Yi -Yi-1). Then the area will be (ΔY-1)*(ΔX-1).
We have to find the maximum area of land(so we exclude the rivers).
Clearly the maximum area would be between the intersection points of (2,4) and (5,2) for the given sample testcase.
Area = | 5 - 2 - 1 | * | 2 - 4 - 1| = 2 * 1 = 2
We implement the formula ,
Area = abs( y2 - y1 - 1) * abs( x2 - x1 - 1)//take abs as area cant be negative
We add an extra -1 in our calculation since we should consider the river area. If we simply implement (y2 - y1) or (x2 - x1) then we would end up counting 1 edge of the vertical river and 1 edge of the horizontal river. We should not include that area as the temple cannot be built over the river edge.