Easy · Intervals
Is overlapped
Given two axis-aligned rectangles with positive width and height, A with bottom-left corner p1 and top-right corner p2 and B with bottom-left corner q1 and top-right corner q2, return true if they share a region of positive area and false otherwise; rectangles that only touch along an edge or at a corner do not overlap.
Examples
Example 1
{
"p1": {
"x": 1,
"y": 1
},
"p2": {
"x": 6,
"y": 6
},
"q1": {
"x": 4,
"y": 3
},
"q2": {
"x": 9,
"y": 7
}
}Output: overlap
Example 2
{
"p1": {
"x": 1,
"y": 1
},
"p2": {
"x": 3,
"y": 8
},
"q1": {
"x": 5,
"y": 2
},
"q2": {
"x": 9,
"y": 6
}
}Output: no overlap
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.