EASY C++ | Using Simple Concept | Explained By Images | in Hinglish
Intuition\n Describe your first thoughts on how to solve this problem. \nWe\'re given a bunch of rectangles, each defined by their bottom-left and top-right coo
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe\'re given a bunch of rectangles, each defined by their bottom-left and top-right coordinates. Now, we want to find pairs of rectangles that overlap with each other. For these overlapping pairs, we\'re interested in figuring out the largest square that fits within their intersection. So, the task is to identify which pairs of rectangles overlap, and then find the biggest square area that fits within the overlapping region of each pair.\n//-------------------------------------------------------------------\nHumko kuch rectangles di gayi hai, har ek ko uske bottom-left aur top-right coordinates se define kiya gaya hai. Ab hume yeh pata lagana hai ki kaunsi rectangles ek doosre se overlap kar rahi hai. In overlapping pairs ke liye, hume unki intersection mein sabse bada square nikalna hai. Toh, humein yeh task hai ki pehle identify karein ki kaunsi rectangles overlap kar rahi hain, aur phir un pairs ki overlapping region mein sabse bada square area nikalein.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThis method looks at each pair of rectangles one after the other to see if they overlap. If they do, it finds the area where they overlap, which forms a smaller rectangle. Then, it calculates the biggest square that can fit inside this smaller rectangle.\n\nImagine two pieces of paper overlapping. We find the area where they overlap and see if we can fit a square in there. We keep track of the biggest square we find while doing this process for all pairs of rectangles.\n//------------------------------------------------------------------\nIterative Comparison: Yeh solution har pair ke rectangles ke saath iterate karta hai, intersections check karne ke liye.\n\nIntersection Check: Har pair ke rectangles ke liye, yeh dekhta hai ki kya woh intersect karte hain. Agar karte hain, toh woh intersection rectangle ke dimensions calculate karta hai.\n\nMaximum Square Area: Intersection rectangle ke andar, solution maximum square area nikalta hai jo ki intersection ki width aur height ka minimum hota hai.\n\nUpdating Maximum Area: Yeh maximum square area ko update karta hai jo ab tak encounter hua hai.\n\n![image.png](https://assets.leetcode.com/users/images/35f899de-68cf-411a-b8f7-4af0c194d5f6_1709756083.4517188.png)\n\n\n# Complexity\n- Time complexity: O(n^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    long long largestSquareArea(vector<vector<int>>& bottomLeft, vector<vector<int>>& topRight) {\n        int ans = 0;\n        int n = bottomLeft.size();\n        for(int i=0;i<n;i++){\n            // first square\'s coordinates\n            int a1 = bottomLeft[i][0];\n            int b1 = bottomLeft[i][1];\n            int x1 = topRight[i][0];\n            int y1 = topRight[i][1];\n            for(int j=i+1;j<n;j++){\n                //second square\'s coordinates\n                int a2 = bottomLeft[j][0];\n                int b2 = bottomLeft[j][1];\n                int x2 = topRight[j][0];\n                int y2 = topRight[j][1];\n                //if NOT intersecting\n                if(a2 >= x1 || a1>=x2) continue;\n                if(b2>=y1 || b1>=y2) continue;\n                //if Intersecting\n                int ansxBL = max(a1,a2);\n                int ansyBL = max(b1,b2);\n                int ansxTR = min(x1,x2);\n                int ansyTR = min(y1,y2);\n                //Possible Side of Square \n                int side1 = ansxTR - ansxBL;\n                int side2 = ansyTR - ansyBL;\n                //Side jo fit Ho skti hai intersecting region me \n        //The side that can fit within the intersecting region.\n                int fitSide = min(side1,side2);\n                //update the Max fitSide in variable "ans"\n                ans = max(ans,fitSide);\n\n            }\n        }\n        return (long long)ans * ans;\n    }\n};\n```
['C++']