Intersection of Two Rectangles
Updated
Problem statement
Each axis-aligned rectangle is represented as [left, bottom, right, top], where left < right and bottom < top.
Return the positive-area intersection of first and second in the same format. If they do not overlap with positive area, return an empty array. Rectangles that only touch along an edge or at one point have no positive-area intersection.
Function
intersectRectangles(first: int[], second: int[]) → int[]Examples
Example 1
first = [0,0,4,4]second = [2,1,6,3]return = [2,1,4,3]The common horizontal interval is [2, 4], and the common vertical interval is [1, 3].
Example 2
first = [-3,-2,5,7]second = [0,0,2,2]return = [0,0,2,2]The second rectangle lies completely inside the first.
Example 3
first = [0,0,2,2]second = [2,0,5,3]return = []The rectangles touch at the vertical edge x = 2 but share no positive area.
Constraints
first.length == second.length == 4.-10^9 <= left < right <= 10^9.-10^9 <= bottom < top <= 10^9.
More Figma Phone Screen questions
- Recursive Display SortPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Route Graph Reachability with a Broken LinkPHONE SCREEN · Seen Oct 2026
- Rich Text Parser Part 3 (Depth Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Rich Text Parser Part 2 (Parse Nested Groups)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Rich Text Parser Part 1 (Validate Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Layer History with Batch Undo and RedoOA · PHONE SCREEN · Seen Sep 2026
- Table Selection and Color UpdatesPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Topmost Accessible NodesPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2025
- Sparse Canvas Paint HistoryPHONE SCREEN · Seen Sep 2023
- Shell Path AutocompletePHONE SCREEN · ONSITE INTERVIEW · Seen May 2022
Similar questions at other companies
- Range of a Third CorrelationTower Research Capital · PHONE SCREEN
- Three Points in a Semicircle: Monte Carlo EstimateSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Union Area of Two RectanglesDocuSign · PHONE SCREENDocuSign interview questions
- Angle Between Clock HandsJane Street · PHONE SCREENJane Street interview questions
- Catching the Bus to the MovieSusquehanna International Group (SIG) · PHONE SCREENSusquehanna International Group (SIG) interview questions
- Light Source Hits: Sample, Compare, and FitOpenAI · PHONE SCREENOpenAI interview questions
- Max Points on a LineUber · PHONE SCREENUber interview questions
- Merge Collinear Point SegmentsApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Count Axis-Aligned and Rotated SquaresGoogle · PHONE SCREENGoogle interview questions
- Best-Fit Plane Normal from 3D PointsThe Voleon Group · PHONE SCREEN