C++ | SIMPLE Solution with Explanation & Diagram
\n\n/*\n\nHarshit Gupta | 10th June, 2021\n---------------------------------\n\nC++ program for "Check if 2 the rectangles overlap with each other"\nReturn fals
```\n\n/*\n\nHarshit Gupta | 10th June, 2021\n---------------------------------\n\nC++ program for "Check if 2 the rectangles overlap with each other"\nReturn false for Not Overlapping\nReturn true      for Overlapping\n\nhttps://leetcode.com/problems/rectangle-overlap/\n------\n\nSolution: Just check the conditions on when they will not overlap and for all other cases they will overlap.\n            1. When R1 is totally on right of R2\n            2. When R1 is totally on left of R2\n            3. When R1 is totally below R2\n            4. When R1 is totally above R2\n\nTime Complexity: O(1)\nSpace Complexity: O(1)\n\nParadigm:\n---\n  NOTE: \n\n*/\n\n//  Case-1: x2 <= x3\n//                               ____________________x4,y4\n//        _____________x2,y2    |                   |\n//       |              |       |___________________|\n//       |______________|      x3,y3\n//      x1,y1\n\n//  Case-2: x4 <= x1\n//                               ____________________x2,y2\n//        _____________x4,y4    |                   |\n//       |              |       |___________________|\n//       |______________|      x1,y1\n//      x3,y3\n\n// Case-3: y2 <= y3\n//        ___________________  x4,y4\n//       |                   |\n//       |                   |\n//       |___________________|\n//     x3,y3         \n//          ___________________x2,y2\n//         |                   | \n//         |___________________|\n//       x1,y1\n\n// Case-4: y4 <= y1\n//        ___________________  x2,y2\n//       |                   |\n//       |                   |\n//       |___________________|\n//     x1,y1         \n//          ___________________x4,y4\n//         |                   | \n//         |___________________|\n//       x2,y3\n\n\nclass Solution {\npublic:\n    bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) {\n        int x1 = rec1[0], y1 = rec1[1], x2 = rec1[2], y2 = rec1[3];\n        int x3 = rec2[0], y3 = rec2[1], x4 = rec2[2], y4 = rec2[3];  \n        \n        // x2 <= x3 when R1 is on the left of R2 and they do not intersect\n        // x4 <= x1 when R2 is on the left of R1 and they do not intersect\n        if(x2 <= x3 || x4 <= x1)\n            return false;\n        \n        // y2 <= y3 when R2 is above R1 and they do not intersect\n        // y4 <= y1 when R1 is above R2 and they do not intersect\n        if (y2 <= y3 || y4 <= y1)\n             return false;\n        \n        // Pathetic conditions added for when the rectangle is just a line\n        if(x1 == x2 || x3 == x4 || y1 == y2 || y3 == y4)\n             return false;\n        \n        return true;\n    }\n};\n```
['C', 'C++']