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
Coding & Algorithms
Software Engineer
SIG
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

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
sweep line
intervals
sorting
event processing
tie-breaking
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported