When a log backend slows down, agents need a bounded buffer and an explicit overflow policy. An unlimited queue can fill the host disk and turn an observability failure into an application outage.
Design a LogBufferSimulator class:
LogBufferSimulator() creates a stateless simulator with an empty initial buffer.int[] bufferLevels(...) returns the buffered count after each interval finishes.int[] droppedPerInterval(...) returns how many arrivals were rejected in each interval.
For interval i, perform operations in this exact order:
arrivals[i] events try to enter the buffer.- Accept only events that fit within
capacity; drop the rest. - Drain up to
drainCapacities[i] buffered events. - Record the remaining buffer and this interval's dropped count.
Drain capacity does not carry into later intervals. Each method call starts with an empty buffer.
Example 1:
Input:
Output:
Explanation: The first interval buffers 5 and drains 3. The next accepts all 8 because 8 slots are free, then drains 3. The final drain clears the remaining 9 events.
Example 2:
Input:
Output:
Explanation: Backlog consumes buffer space. Only four arrivals fit in interval 2 and two fit in interval 3.
Constraints
1 <= arrivals.length == drainCapacities.length <= 10^50 <= arrivals[i], drainCapacities[i], capacity <= 10^9- Buffer calculations fit in a signed 32-bit integer.
- Arrivals are admitted before draining in each interval.
- At most
100 total method calls are made.