Test for a Positive-Area Rectangle Intersection

Quick Overview

Test for a Positive-Area Rectangle Intersection. Each axis-aligned rectangle is [x 1,y 1,x 2,y 2], its bottom-left and top-right corners.

Test for a Positive-Area Rectangle Intersection

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Each axis-aligned rectangle is [x 1,y 1,x 2,y 2], its bottom-left and top-right corners. Return whether rec 1 and rec 2 share positive area. Touching only an edge or corner does not count. ```cpp class Solution { public: bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2); }; ``` ### Examples **Example 1:** ```text rec1 = [-2,-1,2,3], rec2 = [1,0,4,2] Output: true Explanation: Their intersection has corners(1,0) and(2,2), with area2. ``` **Example 2:** ```text rec1 = [0,0,2,2], rec2 = [2,2,4,4] Output: false Explanation: They share only one corner. ``` ### Constraints - Each rectangle array contains four coordinates in [-1000000000,1000000000]. - Both arrays describe valid rectangles with positive width and height. ### Contract considerations Preserve the nonzero-area input rectangle promise. ```hint Read the boundary condition When does an interval intersection have positive length? ``` ### Boundary reminders Preserve the nonzero-area input rectangle promise.

Overview: Test for a Positive-Area Rectangle Intersection. Each axis-aligned rectangle is [x 1,y 1,x 2,y 2], its bottom-left and top-right corners.

Google logo
Google
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Each axis-aligned rectangle is [x 1,y 1,x 2,y 2], its bottom-left and top-right corners. Return whether rec 1 and rec 2 share positive area. Touching only an edge or corner does not count.

class Solution {
public:
    bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2);
};

Examples

Example 1:

rec1 = [-2,-1,2,3], rec2 = [1,0,4,2]
Output: true
Explanation: Their intersection has corners(1,0) and(2,2), with area2.

Example 2:

rec1 = [0,0,2,2], rec2 = [2,2,4,4]
Output: false
Explanation: They share only one corner.

Constraints

  • Each rectangle array contains four coordinates in [-1000000000,1000000000].
  • Both arrays describe valid rectangles with positive width and height.

Contract considerations

Preserve the nonzero-area input rectangle promise.

Boundary reminders

Preserve the nonzero-area input rectangle promise.