Simple & Intuitive Solution (C++ / Rust)
The problem is to find the area of the largest square formed within the intersecting rectangles. Check each pair of rectangles for overlapping by brute-force. Y
The problem is to find the area of the largest square formed within the intersecting rectangles. Check each pair of rectangles for overlapping by brute-force. You can think of the cases when there will be no overlapping between rectangles R1 having bottom left corners `[x1,y1]` and top-right corners `[x2,y2]` and R2 having bottom-left `[a1,b1]` and top-right `[a2,b2]`\n\n* When min-x of R2 `a1` > max-x of R1 `x2`\n* When max-x of R2 `a2` < min-x of R1 `x1`\n* When min-y of R2 `b1` > max-y of R1 `y2`\n* When max-y of R2 `b2` < min-y of R1 `y1`\n\nIn such cases, we will simply skip those pairs of rectangles. Otherwise, `max(bottom-left points)` and `min(top-right points)` will give the coordinates of maximum overlapping area. As we need to find the area of square not rectangle, we have to take `min` of above two and calculate the area by squaring it. Keep track of max-area found so far in `ans` variable. Return the `ans` at last.\n\n\n# C++ Code\n```\nclass Solution {\npublic:\n    #define ll long long\n    long long largestSquareArea(vector<vector<int>>& bl, vector<vector<int>>& tr) {\n    vector<vector<int>> v;\n    for(int i=0; i<bl.size(); i++) {\n        v.push_back({bl[i][0], bl[i][1], tr[i][0], tr[i][1]});\n    }\n    ll ans=0;\n    for(int i=0; i<v.size(); ++i){\n        ll x1=v[i][0], y1=v[i][1];\n        ll x2=v[i][2], y2=v[i][3];\n        for(int j=i+1; j<v.size(); ++j){\n\n            ll a1=v[j][0], b1=v[j][1];\n            ll a2=v[j][2], b2=v[j][3];\n\n            if(a1 > x2 or a2 < x1 or b1 > y2 or b2 < y1) \\\\ no-overlapping\n                continue;\n\n            ll X1=max(x1,a1), Y1=max(y1,b1);\n            ll X2=min(x2,a2), Y2=min(y2,b2);\n            ll mini = abs(min(X2-X1, Y2-Y1));\n            ans = max(ans, mini*mini);\n        }\n    }\n    return ans;\n    }\n};\n```\n\n# Rust Code\n\n```\nimpl Solution {\n    pub fn largest_square_area(bl: Vec<Vec<i32>>, tr: Vec<Vec<i32>>) -> i64 {\n    let mut v: Vec<Vec<i32>> = Vec::new();\n    for i in 0..bl.len() {\n        v.push(vec![bl[i][0], bl[i][1], tr[i][0], tr[i][1]]);\n    }\n    let mut ans: i64 = 0;\n    for i in 0..v.len() {\n        let x1 = v[i][0] as i64;\n        let y1 = v[i][1] as i64;\n        let x2 = v[i][2] as i64;\n        let y2 = v[i][3] as i64;\n        for j in (i + 1)..v.len() {\n\n            let a1 = v[j][0] as i64;\n            let b1 = v[j][1] as i64;\n            let a2 = v[j][2] as i64;\n            let b2 = v[j][3] as i64;\n\n            if a1 > x2 || a2 < x1 || b1 > y2 || b2 < y1 {\n                continue;\n            }\n\n            let X1 = x1.max(a1);\n            let Y1 = y1.max(b1);\n            let X2 = x2.min(a2);\n            let Y2 = y2.min(b2);\n            let mini = (X2 - X1).abs().min((Y2 - Y1).abs());\n            ans = ans.max(mini * mini);\n        }\n    }\n    ans\n    }\n}\n```
['C++', 'Rust']