Group Trading Accounts Into Netting Sets by Shared Agreements
Last updated: November 29, 2026
Quick Overview
Accounts are linked to legal agreements such as ISDA master agreements and credit support annexes, and any accounts connected through a chain of shared agreements net together. Given the links and each account's mark to market, return every netting set with its net exposure, largest absolute exposure first.
DRW
November 29, 20260
0
0 solved
Accounts are linked to legal agreements such as ISDA master agreements and credit support annexes, and any accounts connected through a chain of shared agreements net together. Given the links and each account's mark to market, return every netting set with its net exposure, largest absolute exposure first.
DRW clears and trades bilaterally across many entities, and credit and margin teams care about exposure per netting set rather than per account. This is a union find problem in disguise, and the interviewer checks that you spot the transitive grouping and implement path compression and union by size.
What the Interviewer Expects
- Recognizes transitive grouping as connected components
- Unions accounts through the first account seen per agreement instead of a quadratic pairing
- Implements path compression and union by size
- Includes accounts that have no agreement as singleton sets
- Sorts output deterministically
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Links are added throughout the day: how do you keep netted exposure current without regrouping?
- Agreements can be terminated, which splits groups. Why is that hard for union find and what would you do?
- Compare with BFS over a bipartite account to agreement graph.
- How would you report gross and net exposure together?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: (account, agreement) pairs and exposure[account]. Two accounts are in the same set if a path of shared agreements connects them. Output: list of (sorted accounts, net). Accounts with expo...
High-Level Design
Treat it as connected components. Rather than union every pair on an agreement (quadratic for a big master agreement), remember the first account seen for each agreement and union later accounts with ...