Find Peak Concurrent Open Orders From Order Lifetimes
Last updated: November 29, 2026
Quick Overview
Each order is given as a half-open interval [open_time, close_time). Return the maximum number of orders open at the same instant and the earliest time that maximum is reached.
SIG
November 29, 20260
0
0 solved
Each order is given as a half-open interval [open_time, close_time). Return the maximum number of orders open at the same instant and the earliest time that maximum is reached.
Risk and exchange-connectivity teams at SIG care about how many orders are live at once, because exchanges cap open orders per session and a breach gets orders rejected. The interviewer wants a sweep line with the correct tie-breaking at shared endpoints, since that is where most candidates get the count wrong.
What the Interviewer Expects
- Clarify interval semantics: an order closing at t and one opening at t do not overlap
- Convert intervals to +1 and -1 events and sort them
- Order closes before opens at equal timestamps
- Track the running count and the first time the max is hit
- Discuss the heap alternative and when it is preferable
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
- How would you return the full time ranges where the count equals the maximum?
- If orders stream in live and you must alert when the count exceeds a limit, what changes?
- How would you do this per exchange and per account at once?
- What if timestamps are nanoseconds and there are a billion orders?
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: list of (start, end) pairs with start < end. An order is live on [start, end). Output: (max_live, first_time). Degenerate intervals where end <= start are dropped, since they were nev...
High-Level Design
Turn each order into two events: (start, +1) and (end, -1). Sort by time. Because -1 < +1, Python's tuple sort puts closes before opens at the same timestamp, which encodes the half-open rule fo...