Building an out-of-order risk allocation system in Python
This is a hard coding problem that tests your ability to handle out-of-order event streams — a real constraint in trading infrastructure. The challenge is not just implementing the core logic, but designing data structures that let you query and mutate allocation state correctly even when events arrive scrambled across time.
The problem requires balancing three concerns: tracking multiple overlapping allocations with different lifespans, executing a greedy drain strategy (expiring soonest first) when trades consume allocation, and answering point-in-time queries about available risk. Strong solutions focus on choosing the right data structure to efficiently find active allocations at any timestamp and to manage the state updates that occur when allocations expire or trades execute.
- Interval overlap and time-range queries
- Greedy selection under constraints (earliest expiry)
- State consistency across out-of-order updates
- Handling edge cases (no active allocation, partial consumption, simultaneous boundaries)