An axis-aligned rectangle is given as [x1, y1, x2, y2], where (x1, y1) is its bottom-left corner and (x2, y2) its top-right corner. Two rectangles overlap when the area of their intersection is positive; rectangles that only share an edge or a corner do not overlap. Given rec1 and rec2, return true if they overlap.
An axis-aligned rectangle is given as [x1, y1, x2, y2], where (x1, y1) is its bottom-left corner and (x2, y2) its top-right corner. Two rectangles overlap when the area of their intersection is positive; rectangles that only share an edge or a corner do not overlap. Given rec1 and rec2, return true if they overlap.
Example 1:
Input: {"rec1":[0,0,2,2],"rec2":[1,1,3,3]}
Output: true
Constraints:
rec1.length == 4
rec2.length == 4
−109≤ rec1[i], rec2[i] ≤109
rec1 and rec2 each describe a valid rectangle with non-zero area.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"rec1":[0,0,2,2],"rec2":[1,1,3,3]}
Two rectangles overlap exactly when their shadows on the x axis overlap and their shadows on the y axis overlap. Check each axis separately.