Reported July 2026
Airbnbmath

Rectangle Fit Queries

Reported by candidates from Airbnb's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Airbnb OA. Under 2s to a working solution.
Founder's read

The Airbnb OA reported in July 2026 hands you a rectangle that rotates 90 degrees, and that one detail is the whole problem. You save rectangles, then answer whether every saved one fits in an a x b box. It looks like a data structure question, but it's a running-aggregate trick with a normalization step. If you spot it in two minutes, the rest is ten lines. If you blank, StealthCoder is the safety net running invisibly during the live assessment. Here's the script.

The problem

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 size a × b.
[1, a, b]: determine whether every rectangle saved by earlier operations can fit inside a box of size a × 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 × 3 and 4 × 2.
For the 3 × 4 box, the first rectangle fits as-is, and the second fits after rotation to 2 × 4. The first query therefore returns true.
For the 3 × 2 box, the first rectangle fits after rotation to 3 × 1, but the second rectangle does not fit in either orientation. The second query therefore returns false.
The final result is [true,false].

Constraints
1 ≤ operations.length ≤ 10^5
operations[i].length = 3
operations[i][0] is either 0 or 1.
1 ≤ operations[i][1] ≤ 10^5
1 ≤ operations[i][2] ≤ 10^5

Reported by candidates. Source: FastPrep

Pattern and pitfall

Normalize every rectangle so its dimensions are sorted: small side s, large side l. Keep two running values across all saves: maxSmall, the max of all s, and maxLarge, the max of all l. For a query, sort the box too into (bs, bl). Every rectangle fits if and only if maxSmall <= bs and maxLarge <= bl. Why it works: a rectangle fits with rotation exactly when its sorted sides are each at most the sorted box sides. The two maxima are independent, so you don't store the rectangles. Each operation is O(1), total O(n). The common pitfall is comparing a to a and b to b without sorting, or checking each rectangle per query, which is O(n^2) at 10^5 operations. Empty history returns true, since both maxima start at 0. If your head freezes mid-assessment, StealthCoder can hand you this solution live.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Rectangle Fit Queries cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Airbnb's OA.

Airbnb reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Rectangle Fit Queries FAQ

What's the trick in Rectangle Fit Queries?+

Sort each rectangle's sides so rotation stops mattering. Track the max of the smaller sides and the max of the larger sides across all saved rectangles. A query box, also sorted, fits everything only if both maxima fit within its sorted sides.

How hard is this Airbnb OA question really?+

Easy to medium. The code is short, but the insight about sorting sides and tracking two maxima is what separates a pass from a timeout. Brute force checks every saved rectangle per query and dies at 10^5 operations.

Why not just store all rectangles and check each one?+

With up to 10^5 operations, a mix of saves and queries makes that O(n^2) in the worst case. Since fitting only depends on two maxima, you keep two integers and answer each query in constant time.

What edge cases should I test?+

A query before any save should return true, as in Example 1. Test a square, a box that needs rotation, and a case where one rectangle passes on its small side but fails on its large side, like the 3 x 2 box in Example 2.

How do I prepare for this in 48 hours?+

Practice problems where a transformation removes a choice, like sorting pairs, then keep running maxima or minima. Write this solution once from memory, check the two examples by hand, and confirm you return a boolean array in query order.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Airbnb.

OA at Airbnb?
Invisible during screen share
Get it