Reported September 2026
TikTokdesign

Rectangle Fit Queries

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

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

The TikTok OA reported in September 2026 looks like a geometry puzzle with rotations, but it collapses to two running numbers. If you've got this invite and 48 hours, here's the point: you never need to store the rectangles. Each one fits separately, so only the extremes matter. It's a design-flavored array problem with a stream of operations, and the answer for every query comes from two tracked values. StealthCoder sits invisibly on your screen as a hedge if you blank during the live assessment, but this one is simple enough to own before you start.

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
operations contains at least one row.
operations[i].length = 3.
operations[i][0] is either 0 or 1.
operations[i][1] and operations[i][2] are positive integers.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Normalize every rectangle so its sides are (small, large). A rectangle fits a box if, after normalizing the box the same way, small <= boxSmall and large <= boxLarge. For all saved rectangles to fit, you need the maximum of all the small sides to be <= the box's small side, and the maximum of all the large sides to be <= the box's large side. So keep two variables, maxSmall and maxLarge, both starting at 0. On a type 0 op, update both with min(a,b) and max(a,b). On a type 1 op, append maxSmall <= min(a,b) and maxLarge <= max(a,b). Empty case returns true for free because the maxes are 0. The common pitfall is comparing a to a and b to b without normalizing, or storing every rectangle and rescanning, which is O(n^2). Another trap is taking the max of raw widths and heights separately. Each op is O(1), so the whole thing is O(n). If you freeze under the clock, StealthCoder is there as the safety net.

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 TikTok's OA.

TikTok 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?+

Normalize each rectangle to (min side, max side) and track only the maximum of each across all saves. A box fits everything if its own min side covers the max small side and its max side covers the max large side. No need to store the rectangles.

How hard is this TikTok OA question really?+

Easy once you see the reduction. The statement is wordy and the rotation detail makes people overthink it. The code is about ten lines with two variables. The risk is a careless mistake on orientation, not algorithmic difficulty.

Why is the first example true with no rectangles saved?+

It's vacuous truth. With nothing saved, there's no rectangle that fails to fit, so the answer is true. Starting maxSmall and maxLarge at 0 handles this automatically because 0 is always <= any positive box side.

Why can't I compare width to width and height to height?+

Rotation is allowed, so a 4x2 rectangle fits a 2x4 box. If you don't normalize both the rectangle and the box to (small, large), you'll return false on valid fits. Sorting each pair first removes the orientation problem entirely.

How do I prepare for this in 48 hours?+

Practice streaming-style problems where you keep a small summary instead of raw data. Write this one from scratch twice, test it on the empty case and the second example, and check that you handle each op type in order. That's enough.

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

OA at TikTok?
Invisible during screen share
Get it