Compute minimum resources for overlapping intervals
Company: TripStack
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates understanding of interval overlap reasoning, resource-allocation and scheduling concepts, and proficiency with algorithmic complexity and appropriate data structure choices.
Read the full TripStack Software Engineer interview experience this question came from
Constraints
- 0 <= n <= 200000
- 0 <= start <= end <= 10^9
- Intervals are half-open: [start, end)
- Target time complexity: O(n log n)
- Space complexity: O(n)
Hints
- Sort intervals by start time and use a min-heap of current end times.
- Before placing a new task, pop all end times <= its start (no overlap at equal endpoints).
- The heap size after insertion is the number of servers currently used; track the maximum.
- Alternatively, use a sweep-line over sorted (time, type) events where end events are processed before start events at the same time.