Python check both X and Y projections (overlapping intervals)
Intuition:\nBoth rectangles overlaps if and only if both X and Y projections of them overlaps.\nWhen checking projection, the problem becomes much easier - "doe
Intuition:\nBoth rectangles overlaps if and only if both X and Y projections of them overlaps.\nWhen checking projection, the problem becomes much easier - "does two intervals overlap" ?\nIf we sort intervals by beginning it is even easier, and to make it trivial it is better to catch the only case when they do not overlap.\nIf we know that A starts before B, then the only case they do not overlap is when B starts after A ends:\n```\na1================a2\n                              b1===========b2\n```\n\n```python\n    def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n        def overlap(a1, a2, b1, b2):\n            """ are two intervals overlapping """\n            if a1 < b1:\n                return not (a2 <= b1)\n            else:\n                return not (b2 <= a1)\n        ax1, ay1, ax2, ay2 = rec1\n        bx1, by1, bx2, by2 = rec2\n        # Rectangles are overlaping\n        # iff their both X and Y projects are overlapping\n        return overlap(ax1, ax2, bx1, bx2) and overlap(ay1, ay2, by1, by2)\n```
['Python']