Back to course home
0% completed
Vote For New Content
Rectangle Overlap (easy)
Problem Statement
You are given a rectangle as a list [x1, y1, x2, y2]
, where (x1, y1)
is the coordinate of its bottom-left corner
, and (x2, y2)
is the coordinate of its top-right
corner. The top
and bottom
edges of the rectangle are parallel to the X-axis
, and the left and right edges are parallel to the Y-axis
.
Two rectangles overlap
if the rectangles share a part of the area
; mere touching at edges
or corners
doesn't count.
Given two rectangles rec1
and rec2
, return true
if they overlap
, otherwise return false
.
Examples
-
Example 1:
- Input:
rec1 = [0, 0, 1, 1], rec2 = [1, 1, 2, 2]
- Expected Output:
false
- Justification: The two rectangles touch at a corner but do not share any area, thus they do not overlap.
- Input:
-
Example 2:
- Input:
rec1 = [0, 0, 2, 2], rec2 = [1, 1, 3, 3]
- Expected Output:
true
- Justification: The rectangles share a part of their area, thus they overlap.
- Input:
-
Example 3:
- Input:
rec1 = [1, 1, 3, 3], rec2 = [2, 2, 4, 4]
- Expected Output:
true
- Justification: These rectangles share a central area, thereby confirming overlap.
- Input:
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible