C++ Solution with easy explanation
Consider a 1D overlap (Interval problem).\n         For an overlap to occur necessary condition is\n         \n                 x3,y2          x4,y2\n          
Consider a 1D overlap (Interval problem).\n         For an overlap to occur necessary condition is\n         \n                 x3,y2          x4,y2\n                   |--------------|\n         |--------------|\n         x1,y1         x2,y1\n                  \n         x1 < x3 < x2  && x3 < x2 < x4 \n         \n         Or simplified - x1 < x4 && x3 < x2\n         For 2D case use 1D conditions for both X and Y axes\n         \n         Case-1: Rec2 intersects with Rec1 on top right corner\n    \n                   ____________________x4,y4\n                  |                   |\n           _______|______x2,y2        |\n          |       |______|____________|\n          |      x3,y3   |\n          |______________|\n         x1,y1\n                  \n         Case-2: Rec2 intersects with Rec1 on top left corner\n           ___________________  x4,y4\n          |                   |\n          |            _______|____________x2,y2\n          |___________|_______|           |\n        x3,y3         |                   | \n                      |___________________|\n                    x1,y1\n\n         Case-3: Rec2 intersects with Rec1 on bottom left corner\n         \n                   ____________________x2,y2\n                  |                   |\n           _______|______x4,y4        |\n          |       |______|____________|\n          |      x1,y1   |\n          |______________|\n         x3,y3\n                  \n         Case-4: Rec2 intersects with Rec1 on bottom right corner\n         \n           ___________________  x2,y2\n          |                   |\n          |            _______|____________x4,y4\n          |___________|_______|           |\n        x1,y1         |                   | \n                      |___________________|\n                    x3,y3\n        \n        bool case1 = (x1 < x4 && x3 < x2 && y1 < y4 && y3 < y2); //top right intersection\n        bool case2 = (x3 < x2 && x1 < x4 && y1 < y4 && y3 < y2); //top left intersection\n        bool case3 = (x3 < x2 && x1 < x4 && y3 < y2 && y1 < y4); //bottom left intersection\n        bool case4 = (x1 < x4 && x3 < x2 && y3 < y2 && y1 < y4); //bottom right intersection\n        \n        if you look carefully in all cases we have same 4 comparisons\n```\nbool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) {\n\tint x1 = rec1[0], y1 = rec1[1], x2 = rec1[2], y2 = rec1[3];\n\tint x3 = rec2[0], y3 = rec2[1], x4 = rec2[2], y4 = rec2[3];\n\treturn (x1 < x4 && x3 < x2 && y1 < y4 && y3 < y2);\n}\n```
[]