




Sponsored
Sponsored
This approach checks if there are conditions that confirm non-overlapping rectangles. Specifically, two rectangles do not overlap if:
If any of these conditions are true, the rectangles do not overlap. Otherwise, they do overlap.
Time Complexity: O(1), since the operation involves a constant number of comparisons.
Space Complexity: O(1), since the space used by the function is constant with respect to inputs.
1def isRectangleOverlap(rec1, rec2):
2    return not (rec1[2] <= rec2[0] or  
3                rec1[0] >= rec2[2]The function checks whether any of the non-overlapping conditions are true. If none are true, it means the rectangles overlap.
This approach computes the potential intersecting rectangle and verifies if its calculated dimensions form a valid rectangle with a positive area. The logic involves:
max(rec1[0], rec2[0])min(rec1[2], rec2[2])max(rec1[1], rec2[1])min(rec1[3], rec2[3])Time Complexity: O(1)
Space Complexity: O(1)
1    bool xOverlap = Math.Min(rec1[2], rec2[2]) > Math.Max(rec1[0], rec2[0]);
    bool yOverlap = Math.Min(rec1[3], rec2[3]) > Math.Max(rec1[1], rec2[1]);
    return xOverlap && yOverlap;
}The C# method ensures overlapping in both x and y dimensions effectively create a valid rectangle with non-zero area.