Rust/Python intersection of two rectangles
Intuition\n\nAs the $n^2$ solutions are enough, you can just take all pairs and check the intersection of rectangles. Which becomes the most important question.
# Intuition\n\nAs the $n^2$ solutions are enough, you can just take all pairs and check the intersection of rectangles. Which becomes the most important question. Once the intersection is found the side will be `min(y, x)` which you should square to find the area.\n\nAs the actions you do on axes are symmetric, it is enough to explain the logic for one axis (let it be `x`). \n\nTo do this you find the position of the low intersection point: `max(bl[i][0], bl[j][0])` and the value of the high intesection point `min(tr[i][0], tr[j][0])`. Of course low should be <  high.\n\n\n# Complexity\n- Time complexity: $O(n^2)$\n- Space complexity: $O(1)$\n\n# Code\n```Rust []\nimpl Solution {\n  pub fn largest_square_area(bl: Vec<Vec<i32>>, tr: Vec<Vec<i32>>) -> i64 {\n    let (mut res, n) = (0, bl.len());\n    for i in 0 .. n - 1 {\n      for j in i + 1 .. n {\n        let x_min = bl[i][0].max(bl[j][0]);\n        let x_max = tr[i][0].min(tr[j][0]);\n        let y_min = bl[i][1].max(bl[j][1]);\n        let y_max = tr[i][1].min(tr[j][1]);\n\n        if x_min < x_max && y_min < y_max {\n          let s = (x_max - x_min).min(y_max - y_min) as i64;\n          res = res.max(s * s);\n        }\n      }\n    }\n\n    return res;\n  }\n}\n```\n```python []\nclass Solution:\n  def largestSquareArea(self, bl: List[List[int]], tr: List[List[int]]) -> int:\n    res, n = 0, len(bl)\n    for i in range(n - 1):\n      for j in range(i + 1, n):\n        x_min, x_max = max(bl[i][0], bl[j][0]), min(tr[i][0], tr[j][0])\n        y_min, y_max = max(bl[i][1], bl[j][1]), min(tr[i][1], tr[j][1])\n        if x_min < x_max and y_min < y_max:\n          res = max(res, min(x_max - x_min, y_max - y_min)**2)\n    \n    return res\n```\n
['Python', 'Rust']