FastPrepRectangle Overlap
Problems/Rectangle Overlap

Rectangle Overlap

Microsoft logoMicrosoft● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This was the human-resources interview of a Microsoft software engineering internship process, as its single DSA question, per a review. The task as reported is to decide from their coordinates whether two rectangles overlap.

The review does not say how a rectangle is described, whether it can be tilted, or whether touching counts. Here both rectangles have sides parallel to the axes and are given by their bottom-left and top-right corners as [x1, y1, x2, y2] with coordinates from -10^9 to 10^9. They intersect only when the shared region has positive area (touching does not count), and you return true or false.

Our version is about 85% the same as the reported question.

Each rectangle has sides parallel to the axes and is given as [x1, y1, x2, y2], where (x1, y1) is its bottom-left corner and (x2, y2) is its top-right corner.

Given two rectangles rec1 and rec2, return true if they intersect and false otherwise. Two rectangles intersect when the region they share has a positive area. Rectangles that only touch along an edge or at a corner do not intersect.

Function

isRectangleOverlap(rec1: int[], rec2: int[]) → boolean

Examples

Example 1

rec1 = [0,0,4,3]rec2 = [2,1,6,5]return = true

The x-ranges 0 to 4 and 2 to 6 share 2 to 4, and the y-ranges 0 to 3 and 1 to 5 share 1 to 3. The rectangles share the 2 by 2 square from (2, 1) to (4, 3), so the answer is true.

Example 2

rec1 = [0,0,2,2]rec2 = [2,0,4,2]return = false

The rectangles meet along the line x = 2 but share no area, so the answer is false.

Example 3

rec1 = [-1,-5,1,5]rec2 = [-5,-1,5,1]return = true

The rectangles form a plus sign. No corner of either rectangle is inside the other, but they share the square from (-1, -1) to (1, 1), so the answer is true.

Constraints

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

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Correct Three Protractor ReadingsSusquehanna International Group (SIG) · ONSITE INTERVIEWSusquehanna International Group (SIG) interview questions
  • Overlap Area of Two RectanglesNutanix · ONSITE INTERVIEWNutanix interview questions
  • Common Part of Two RectanglesExpedia · ONSITE INTERVIEWExpedia interview questions
  • Optimal Central WarehouseGoogle · ONSITE INTERVIEWGoogle interview questions
  • Max Points on a LineLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Rasterize a Circle with Integer PixelsPure Storage · ONSITE INTERVIEWPure Storage interview questions
  • Point Inside a TriangleSambaNova Systems · PHONE SCREEN · ONSITE INTERVIEWSambaNova Systems interview questions
  • Circle Intersection in Three DimensionsNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Range of a Third CorrelationTower Research Capital · PHONE SCREEN
  • Three Points in a Semicircle: Monte Carlo EstimateSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
        // Write your code here.
    }
}
Checking account…