Check if Rectangles Overlap

Given two axis-aligned rectangles, check if they overlap.

Statement

Given the bottom-left and top-right coordinates of two axis-aligned rectangles, check if the two rectangles overlap. Return true if they overlap, otherwise, return false.

Note: Two rectangles that only touch at the corner or edges do not overlap.

Example

In the following example, we have two overlapping rectangles: Rectangle1 and Rectangle2.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.