Rectangle Fit Queries
Reported by candidates from Capital One's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The edge case that breaks a naive solution here is the empty query: a Capital One OA reported in September 2026 asks whether every saved rectangle fits a box, and when nothing's saved yet, the answer is true. Most people loop over all saved rectangles on every query and time out at 10^5 operations. This is a design-flavored array problem with a simple core trick. Normalize each rectangle, track two numbers, answer in O(1). If you blank mid-assessment, StealthCoder runs invisibly on your desktop as a safety net and hands you the solution while you keep typing.
The problem
Process the rows of operations 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. Test each saved rectangle separately; the rectangles do not need to fit in the box at the same time. You may rotate a rectangle by 90 degrees. Return one boolean for each query operation, in query order. Function solution(operations: int[][]) → boolean[] Examples Example 1 operations = [[1,1,1]] return = [true] No rectangles have been saved, so every saved rectangle vacuously fits and the answer is true. Example 2 operations = [[0,1,3],[0,4,2],[1,3,4],[1,3,2]] return = [true,false] Both saved rectangles fit the 3 × 4 box after choosing the appropriate orientation. The 4 × 2 rectangle cannot fit the later 3 × 2 box, so the answers are [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
The trick: rotation is allowed, so normalize every rectangle to (small, large) with small = min(a,b) and large = max(a,b). Keep two running maximums across all saved rectangles: maxSmall and maxLarge. For a query, normalize the box the same way, then answer true if maxSmall <= boxSmall and maxLarge <= boxLarge. Why it works: a rectangle fits in either orientation exactly when its sorted dimensions are each at most the box's sorted dimensions. Rectangles are tested separately, so per-dimension maximums are enough. The pitfall is forgetting to sort the box dimensions, or scanning every saved rectangle per query. Initialize both maximums to 0 so the empty case returns true on its own. Total time is O(n), space O(1) beyond the output. If the sorted-pair logic slips away under the clock, StealthCoder is the hedge that surfaces it live.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Capital One's OA.
Capital One reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Rectangle Fit Queries FAQ
How hard is Rectangle Fit Queries really?+
Easy once you see it. The code is about ten lines. The difficulty is spotting that you only need two running maximums instead of storing every rectangle. If you store them all and scan per query, you'll hit 10^5 times 10^5 and fail on time.
What's the trick to the rotation part?+
Sort each pair so the smaller side comes first. A rectangle fits a box if its smaller side is at most the box's smaller side and its larger side is at most the box's larger side. That one comparison covers both orientations, so you never test rotations separately.
What should the answer be when no rectangles are saved?+
True. Example 1 shows it: a query on an empty set is vacuously true. If you initialize maxSmall and maxLarge to 0, every box with positive dimensions passes naturally and you need no special case.
Do the rectangles need to fit in the box together?+
No. The problem says each saved rectangle is tested separately. That's why tracking the maximum small side and maximum large side is enough. You're not packing anything, just checking that no single rectangle exceeds the box.
How do I prepare for this in 48 hours?+
Practice the pattern of keeping running aggregates instead of rescanning history. Write this one from scratch twice, including the empty-query case. Also check your output is a boolean array containing only query results, not one entry per operation.