Reported September 2026
Citadeltwo pointers

Reconcile Unmatched Trades with Timestamp Tolerance

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

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

Citadel reportedly served this one in September 2026, and the detail that matters is the matching rule: buys and sells only pair when symbol, priceCents and quantity are identical and timestamps sit within tolerance. That turns one big problem into many tiny ones. If your OA lands this week, this is a group-then-two-pointer walk, not a graph matching problem. Up to 200000 rows means you can't brute force pairs. StealthCoder is the safety net on the live OA if the tie-breaking rules make you blank, but the logic below is short enough to carry in your head.

The problem

Given a finite batch of trade records, pair compatible buy and sell trades and return the IDs of every trade that remains unmatched.
Each row of trades contains exactly six strings in this order:
tradeId: a unique identifier.
symbol: the traded instrument.
side: either BUY or SELL.
priceCents: a positive integer price in cents.
quantity: a positive integer quantity.
timestamp: a nonnegative integer timestamp.
A buy and a sell are compatible when they have the same symbol, priceCents, and quantity, and the absolute difference between their timestamps is at most tolerance. Each trade may be paired at most once, and partial fills are not used.
Within each shared symbol-price-quantity key, consider buys and sells in ascending timestamp order, breaking equal timestamps by original input position. Pair the earliest remaining buy with the earliest remaining sell whenever they are within the tolerance window. If one is earlier than the other by more than tolerance, that earlier trade is unmatched.
Return all unmatched tradeId values in their original input order.

Function
findUnmatchedTrades(trades: String[][], tolerance: long) → String[]

Examples
Example 1
trades = [["b1","AAPL","BUY","10000","5","100"],["s1","AAPL","SELL","10000","5","102"],["b2","MSFT","BUY","25000","2","200"],["s2","MSFT","SELL","25000","2","206"],["b3","AAPL","BUY","10000","7","105"]]
tolerance = 2
return = ["b2","s2","b3"]
b1 and s1 share their symbol, price, and quantity, and their timestamps differ by 2, so they pair. The two MSFT trades differ by 6, and b3 has no sell with quantity 7.
Example 2
trades = [["b1","XYZ","BUY","500","1","10"],["b2","XYZ","BUY","500","1","12"],["s1","XYZ","SELL","500","1","11"],["s2","XYZ","SELL","500","1","20"]]
tolerance = 1
return = ["b2","s2"]
The earliest buy b1 pairs with the earliest sell s1. The remaining timestamps 12 and 20 are outside the tolerance window.

Constraints
1 <= trades.length <= 200000.
Every row contains exactly six values in the documented order.
Every tradeId is unique and every symbol and tradeId is non-empty.
side is either BUY or SELL.
1 <= priceCents, quantity <= 10^9.
0 <= timestamp, tolerance <= 10^15.
Numeric row fields are canonical base-10 integer strings without signs or separators.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Group trades by the composite key symbol|price|quantity. Inside each group, split into buys and sells, sort each by timestamp, then by original index. Walk two pointers. If the buy timestamp and sell timestamp differ by at most tolerance, pair them and advance both. Otherwise the earlier one is stuck forever, because every later opposite trade is even further away, so mark it unmatched and advance only that pointer. Leftovers at the end are unmatched. Finally, scan the original input and output IDs in input order. Pitfalls: timestamps and tolerance go up to 10^15, so parse as long. Don't build the key by joining without a separator, or you'll collide. Don't output unmatched IDs in sorted order. Complexity is O(n log n) from the sorts. Example 2 is the one to trace by hand, since b1 pairs with s1 and leaves b2 behind.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Reconcile Unmatched Trades with Timestamp Tolerance 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 would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Citadel reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Reconcile Unmatched Trades with Timestamp Tolerance FAQ

What's the trick in the Citadel trade reconciliation problem?+

Bucket by symbol, price and quantity, then run a two-pointer merge on sorted buys and sells inside each bucket. The earlier trade out of tolerance range can never match anything later, so you drop it immediately. No search or backtracking is needed.

How hard is this really?+

Medium. The logic is simple once you see the grouping, but the tie-breaking rules and large numeric ranges create easy mistakes. Most failures come from sorting order, long overflow, or returning IDs in the wrong order.

Why not match each buy against every sell?+

With up to 200000 trades, a single hot key could hold most of them, making pairwise comparison quadratic. Sorting plus two pointers gives O(n log n) and also follows the earliest-with-earliest rule the statement demands.

How do I handle equal timestamps?+

Break ties by original input position. Sort each side by the tuple of timestamp and index. Store the index with each trade when you group, so the stable ordering is explicit rather than relying on sort behavior.

How do I prepare in 48 hours?+

Write this once from scratch: map of key to buy list and sell list, sort, two-pointer loop, mark matched in a boolean array, then scan input order. Test both examples, plus a case with equal timestamps and a case with tolerance 0.

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

OA at Citadel?
Invisible during screen share
Get it