Reported September 2026
Hudson River Tradingdesign

Rectangle Fit Queries

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

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

Hudson River Trading reportedly put Rectangle Fit Queries in front of candidates in September 2026, and the whole question hinges on what you store, not how many rectangles you save. You process a stream of add and query operations. Each query asks if every saved rectangle fits a box, with rotation allowed. The trick is that you never need the list of rectangles. Two running numbers answer every query. If you blank on that, StealthCoder is the quiet safety net on the live OA, but the idea fits in about ten lines.

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 short side is first and its long side is second. Keep two values: maxShort, the largest short side seen, and maxLong, the largest long side seen. For a query, normalize the box the same way into boxShort and boxLong. Every rectangle fits if and only if maxShort <= boxShort and maxLong <= boxLong. That works because each rectangle is checked on its own, and sorted sides are the best orientation for a fit. With no saved rectangles, initialize both maxes to 0 so the answer is true. The common pitfall is storing all rectangles and rescanning on each query, which is slow. Another is forgetting to normalize the box, so a 4 x 3 box fails wrongly. Each operation is O(1). If your head goes blank mid-OA, StealthCoder can hand you this solution from the screen without the proctor seeing it.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Hudson River Trading's OA.

Hudson River Trading reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Rectangle Fit Queries FAQ

What's the trick in Rectangle Fit Queries?+

Track only two numbers: the largest short side and the largest long side across all saved rectangles. Sort each rectangle's dimensions when you save it. A query passes if both maxima fit within the box's sorted dimensions. No list of rectangles is needed.

How hard is this problem really?+

Easy once you see the reduction, and it's mostly a recognition problem. The code is short, and there's no heavy algorithm. People who struggle usually try to store every rectangle or check orientations one by one. Spend your thinking time on why sorted sides work.

How do I handle the empty case?+

Start both maximums at 0. A query before any save then compares 0 against the box sides, which always passes, so you return true. This matches Example 1, where [1,1,1] returns [true]. Don't special-case it with a separate branch.

Does rotation break the max-tracking approach?+

No. Rotation is handled by sorting. Put the smaller side first for both the rectangle and the box. A rectangle fits a box with rotation only if its smaller side is at most the box's smaller side and its larger side is at most the box's larger side.

How should I prepare for this in 48 hours?+

Practice streaming problems where you keep summary state instead of raw data. Write this one from scratch twice, then test Example 2 by hand: maxShort 2, maxLong 4, box 3x4 passes, box 3x2 fails. Also check edge cases like square rectangles and repeated queries.

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

OA at Hudson River Trading?
Invisible during screen share
Get it