Rectangle Overlap

EasyMathmath

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

An axis-aligned rectangle is given as [x1, y1, x2, y2], where (x1, y1) is its bottom-left corner and (x2, y2) its top-right corner, with x1 < x2 and y1 < y2. Given two such rectangles rec1 and rec2, return true if their intersection has **positive area**, and false otherwise. Rectangles that only touch along an edge or at a corner do not overlap.

Examples

Input: rec1 = [0,0,2,2], rec2 = [1,1,3,3]
Output: true
They share the 1x1 square [1,1,2,2].
Input: rec1 = [0,0,1,1], rec2 = [1,0,2,1]
Output: false
They only touch along the line x = 1.
Input: rec1 = [0,0,1,1], rec2 = [2,2,3,3]
Output: false
They are far apart.

Constraints

  • rec1.length == rec2.length == 4
  • -10^9 <= rec1[i], rec2[i] <= 10^9
  • Each rectangle has `x1 < x2` and `y1 < y2`

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More math problems