Flag Self Matches and Round Trip Trades Between Linked Accounts
Last updated: November 29, 2026
Quick Overview
Given a time-ordered list of trades with buyer and seller account ids and a mapping from account to beneficial owner, flag trades where the same owner is on both sides, and trades that reverse an earlier trade between the same two owners in the same symbol within a time window.
Gemini
November 29, 20260
0
0 solved
Given a time-ordered list of trades with buyer and seller account ids and a mapping from account to beneficial owner, flag trades where the same owner is on both sides, and trades that reverse an earlier trade between the same two owners in the same symbol within a time window.
As a regulated exchange, Gemini runs market surveillance for manipulative patterns such as wash trading. This Python data question checks whether a candidate can turn a compliance rule into an efficient streaming pass and reason about false positives.
What the Interviewer Expects
- Resolve accounts to beneficial owners before comparing sides
- Detect same-owner trades directly
- Use a sliding window per (symbol, owner pair) for round trips instead of comparing all pairs
- Require the opposite direction (A bought from B, then B bought from A)
- Discuss thresholds and false positives such as market makers trading with each other
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you add a quantity or price similarity condition to the round trip rule?
- How would you run this over a full day of trades in Spark?
- How would you rank alerts so investigators look at the riskiest first?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Each trade has ts (seconds), symbol, buyer, seller, qty and is sorted by time. owner_of maps account id to beneficial owner (linked sub-accounts or related entities share an owner). Output...
Approach
One pass. Self match: owners equal. Round trip: key the window by symbol plus the unordered owner pair, keep a deque of recent (ts, buyer_owner, index), evict entries older than the window, and flag...