Merge timestamped price changes into a cumulative price series
Company: Citadel
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: Merge sorted streams of timestamped price changes into one cumulative price series. Combine simultaneous changes before output, preserve zero-net-change timestamps, and handle empty streams and negative values.
Constraints
- There are between 0 and 10000 streams and at most 100000 records in total.
- `0 <= timestamp <= 1000000000`.
- Changes and `initial_price` are between -1000000000 and 1000000000.
- Resulting prices may exceed signed 32-bit range but have absolute value at most 100001000000000, below the exact-integer limit of `2 ** 53`.
Examples
Input: ([[[1, 5], [3, -2]], [[1, -1], [2, 4]], []], 10)
Expected Output: [[1, 14], [2, 18], [3, 16]]
Explanation: All changes at timestamp one apply before emitting its price.
Input: ([[[2, 3], [2, -3]]], -4)
Expected Output: [[2, -4]]
Explanation: A same-stream cancellation still emits its timestamp.
Hints
- At any step, the next unseen record from each nonempty stream has its stream's lowest remaining timestamp.
- Advance every record at the current timestamp before emitting its price.