Easy Solution Explained || Python 3 || O(1) Space Complexity
Approach\n Describe your approach to solving the problem. \nPlease read the comments provided in code to get easy understanding of the approach.\n1. Find the Co
# Approach\n<!-- Describe your approach to solving the problem. -->\nPlease read the comments provided in code to get easy understanding of the approach.\n1. Find the Common region between any two rectangles (cover all possible comparision of two rectangles). \n- How to cover all possible comparision of two rectangles? \n- :) Just iterate in two loops.\n- Why only two rectangles?\n- As Two rectangles intersection gives us a rectangular region.\n- So what if two or more rectangles intersect won\'t they give you maximum square region?\n- First, let me ask you a question from the concept of set\'s. \n- Q) Will the number of elements in intersection of two sets (a,b) is less than the number of elements in intersection of three sets (a,b,c)?\n- Ans) No, the number of elements in intersection of two sets (a,b) is always greater than or equal to the number of elements in intersection of three sets (a,b,c),...etc.\n- What do you understand from above concept of sets? \n- The common region between two rectangles follows the same concept of the intersection of b/w sets. So, considering the common region formed by all two possible rectangles is good enough to our problem.\n\n2. Just Calculate the sides i.e., width and height of the common region formed from the intersection of two rectangles.\n- what is a maximum possible square inside a rectangle region? The minimum side of rectangle gives us the largest possible side of a square and square of this side gives the maximum area of square in that region.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n***O(n^2)***\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n***O(1)***\n# Code\n```\nclass Solution:\n    def largestSquareArea(self, bottomLeft: List[List[int]], topRight: List[List[int]]) -> int:\n        n = len(bottomLeft)\n        max_side = 0\n        for i in range(n):\n            # any two squares comparision\n                \n                # Condition where we fix the boundary for the common region between two rectangles \n                # - Rect 1\'s bottom should be less than or equal to the Rect 2\'s top\n                # - Rect 1\'s top should be greater than or equal to the Rect 2\'s bottom\n                # Only this region will be the common area. \n                # You might think, what if there are 3 or more rectangles and their intersection is forming more area.\n                # Basically 2 rectangles intersection already gives you a region as we are doing brute-force the case where the rectangle\'s intersection with largest region as their intersection is already covered.\n                \n            for j in range(i + 1, n):\n                if bottomLeft[i][0] <= topRight[j][0] and bottomLeft[j][0] <= topRight[i][0] and bottomLeft[i][1] <= topRight[j][1] and bottomLeft[j][1] <= topRight[i][1]:\n                    # select maximum bottom of the two to select the common square fields bottom it is always less than or equal to minimum bottom of two\n                    bottom_x = max(bottomLeft[i][0], bottomLeft[j][0])\n                    # select minimum top of the two to select the common square fields top as it is always less than or equal to maximum top of two\n                    top_x = min(topRight[i][0], topRight[j][0])\n                    # select maximum bottom of the two to select the common square fields bottom it is always less than or equal to minimum bottom of two\n                    bottom_y = max(bottomLeft[i][1], bottomLeft[j][1])\n                    # select minimum top of the two to select the common square fields top as it is always less than or equal to maximum top of two\n                    top_y = min(topRight[i][1], topRight[j][1])\n                    # difference of top_x and bottom_x gives width (imagine two vertical lines and the distance between these gives width)\n                    width = top_x - bottom_x\n                    # difference of top_y and bottom_y gives height (imagine two horizontal lines and the distance between these gives height)\n                    height = top_y - bottom_y\n                    # This side is needed because for square to be formed in a region we need both height and width to be same, so we select min of the two which indeed gives square when multiplied this minimum side by itself.\n                    AtleastSide = min(width,height)\n                    # compare previous max_side with current side we got from this iteration \n                    max_side = max(max_side, AtleastSide)\n        return (max_side*max_side) # area of square s*s\n```
['Math', 'Python3']