[C++/Java/Python] 1-line Solution, 1D to 2D
Intuition:\nBefore we do it in 2D plane, let\'s try it in 1D.\nGiven 2 segment (left1, right1), (left2, right2), how can we check whether they overlap?\nIf thes
# **Intuition**:\nBefore we do it in 2D plane, let\'s try it in 1D.\nGiven 2 segment `(left1, right1)`, `(left2, right2)`, how can we check whether they overlap?\nIf these two intervals overlap, it should exist an number `x`,\n\n`left1 < x < right1 && left2 < x < right2`\n\n`left1 < x < right2 && left2 < x < right1`\n\n`left1 < right2 && left2 < right1`\n\nThis is the sufficient and necessary condition for two segments overlap.\n<br>\n\n# **Explanation**:\nFor 2D, if two rectancle overlap both on `x` and `y`, they overlap in the plane.\n<br>\n\n# **Complexity**:\nTime O(1)\nSpace O(1)\n<br>\n\n**C++/Java:**\n```\nreturn rec1[0] < rec2[2] && rec2[0] < rec1[2] && rec1[1] < rec2[3] && rec2[1] < rec1[3];\n```\n**Python:**\n```\nreturn rec1[0] < rec2[2] and rec2[0] < rec1[2] and rec1[1] < rec2[3] and rec2[1] < rec1[3]\n```\n<br>\n\n# Note\n@pgmreddy mentioned that the following solution will fail under this contraints:\nFor example:\n[-1,0,1,1]\n[0,-1,0,1]\n\nI didn\'t fix it forward,\nBecuase the current contraints badly defined that a rectangle area can be zero,\nwhile it also says the common area needs to be positive.\n<br>
[]