Input : N rectangles. The coordinates for the rectangles are given.
Output : To check whether they form a square or not.
- There can be overlapping among the rectangles.
I have solved for the case in which rectangles are parallel to the X and Y axis.
Soln :
Since the area of square is a perfect square ,so (Sum of area of total rectangles - Overlapping in between them ) should be a perfect square.
Now find the min. value of X coordinate of all the rectangles and max. value of Y coordinate. If they form a square then | min(x)-max(y) | is the length of the square. Now just find the sum of the area of the rectangles considering the overlaps. If it's equal to area of square with length | min(x)-max(y) |. Bingo !!
Complexity : O(n*n)
How to solve for general case ?