Interval intersection 7-line C++
Approach\nWhile considering the intersection of any two squares (or rectangles), the width and height can be thought of independently. Both follow the pattern i
# Approach\nWhile considering the intersection of any two squares (or rectangles), the width and height can be thought of independently. Both follow the pattern in finding the intersection of two intervals.\n\nLet `a` and `b` be two intervals, size of the intersection can be calculated with `max(0, min(a.end, b.end) - max(a.begin, b.begin))`. Similarly, in our case of squares, the width and height can be calculated with `w = max(0, min(a.right, b.right) - max(a.left, b.left))` and `h = max(0, min(a.top, b.top) - max(a.bottom, b.bottom))`, respectively. Then `min(w, h)` is the size of square that can fit into the intersection.\n\n# Complexity\n- Time complexity:\n$$O(n^2)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```cpp []\nlong long largestSquareArea(vector<vector<int>>& lb, vector<vector<int>>& tr) {\n    int n = lb.size(), ans = 0;\n    for (int i = 0; i < n; i++)\n        for (int j = i + 1; j < n; j++) {\n            int w = max(0, min(tr[i][0], tr[j][0]) - max(lb[i][0], lb[j][0]));\n            int h = max(0, min(tr[i][1], tr[j][1]) - max(lb[i][1], lb[j][1]));\n            ans = max(ans, min(w, h));\n        }\n    return (long long)ans * ans;\n}\n```
['C++']