Ctrl K

Do Two Frames Overlap

Easy
An axis-aligned rectangle is written as a list [x1, y1, x2, y2], where (x1, y1) is its bottom-left corner and (x2, y2) its top-right corner. You get two such rectangles, first and second. Return True if they share a region of positive area, and False otherwise. Rectangles that only touch at an edge or a corner do not overlap.
Example 1
first=[0, 0, 4, 3], second=[2, 1, 6, 5] → True

They share the rectangle from (2, 1) to (4, 3), whose area is 4.

Example 2
first=[0, 0, 2, 2], second=[2, 0, 4, 2] → False

The rectangles only touch along the edge x = 2, so the shared area is zero.

Constraints
  • len(first) == len(second) == 4
  • -10⁹ ≤ first[i], second[i] ≤ 10⁹
  • x1 < x2 and y1 < y2 for each rectangle
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Biggest Triangle on the Board EasyShadows of Block Towers EasySurface of Cube Towers EasyHow a Rumor Spreads EasyThree Stakes Off the Line Easy
loading Python…
Input
first=[0, 0, 4, 3], second=[2, 1, 6, 5]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 119 tests on the server, hidden ones included.