Problem · Array
Rectangle Fit Queries
Learn this problemProblem statement
You are given an integer matrix operations. Process its rows from left to right. Each row has one of two forms:
[0, a, b]: create and save a rectangle of sizea × b.[1, a, b]: determine whether every rectangle saved by earlier operations can fit inside a box of sizea × b.
For a query, test each saved rectangle separately; the rectangles do not need to fit in the box at the same time. You may rotate any saved rectangle by 90 degrees, changing dimensions x × y to y × x.
Return a boolean array containing the answers to all query operations in the order they appear.
Function
canFitSavedRectangles(operations: int[][]) → boolean[]Examples
Example 1
operations = [[1,1,1]]return = [true]No rectangles have been saved before the query, so every saved rectangle fits and the answer is true.
Example 2
operations = [[0,1,3],[0,4,2],[1,3,4],[1,3,2]]return = [true,false]- Save rectangles of sizes
1 × 3and4 × 2. - For the
3 × 4box, the first rectangle fits as-is, and the second fits after rotation to2 × 4. The first query therefore returnstrue. - For the
3 × 2box, the first rectangle fits after rotation to3 × 1, but the second rectangle does not fit in either orientation. The second query therefore returnsfalse.
The final result is [true,false].
Constraints
1 ≤ operations.length ≤ 10^5operations[i].length = 3operations[i][0]is either0or1.1 ≤ operations[i][1] ≤ 10^51 ≤ operations[i][2] ≤ 10^5
More Airbnb problems
- Most Frequent Reduced DigitOA · Seen Jul 2026
- Robot Final DirectionOA · Seen Jul 2026
- Robot Inventory TrackingOA · Seen Jul 2026
- Parse Query StringPHONE SCREEN · Seen May 2026
- Print Sentences as TablePHONE SCREEN · Seen May 2026
- Minimum Eating SpeedSeen Mar 2024
- Minimum MovesSeen Dec 2022
- Donut ChallengeSeen Dec 2022