Process pod logs with global increments and pop-min
Company: Confluent
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
You are given an event log for a system of “pods.” Each event is a pair `[status, value]`:
- `status == 1`: Add a new pod with **initial load** = `value`.
- `status == 2`: Increase the load of **every existing pod** by `value` (a global increment).
- `status == 3`: Remove the pod with the **smallest current load** and **output/record** that pod’s current load. (For `status == 3`, the `value` field can be ignored.)
Return a list of the loads produced by every `status == 3` operation, in order.
### Example
Input:
`logs = [[1, 5], [1, 2], [2, 3], [3, 0], [3, 0]]`
Process:
- add pod(5)
- add pod(2)
- +3 to all ⇒ loads become (8, 5)
- pop min ⇒ output 5
- pop min ⇒ output 8
Output: `[5, 8]`
### Notes / assumptions
- It is guaranteed that a `status == 3` event will not occur when there are no pods.
- Use 64-bit integers if needed.
- Aim for an efficient solution (e.g., better than O(n) per global increment).
Quick Answer: This question evaluates understanding of data structures—particularly priority queues/heaps—and techniques for efficiently handling global/bulk updates and minimum extraction under changing offsets.
Process pod loads: add inserts a load, inc changes every active load, and pop removes the smallest current load. Return pop outputs; empty pop returns None.
Constraints
- Inputs are provided as Python literals compatible with the function signature.
- Return a deterministic value exactly matching the requested output.
Examples
Input: ([['add', 5], ['add', 2], ['inc', 3], ['pop'], ['add', 1], ['pop'], ['pop']],)
Expected Output: [5, 1, 8]
Explanation: Global increment then pops.
Input: ([['pop'], ['add', 4], ['inc', -1], ['pop']],)
Expected Output: [None, 3]
Explanation: Empty pop and negative increment.
Input: ([['add', 10], ['add', 10], ['inc', 5], ['pop'], ['pop']],)
Expected Output: [15, 15]
Explanation: Ties.
Hints
- Start with a direct data structure representation.
- Handle edge cases before the main loop.