FastPrepFastPrep
Problem Brief

Count Dropped Requests

FULLTIMEOA

A server maintains a pool of processing threads. The input array describes events in chronological order.

  • A positive value adds that many threads to the pool.
  • -1 means a request arrives.

Each thread can serve at most one request and is then destroyed. If a request arrives when no threads are available, that request is dropped.

Return the number of dropped requests.

1Example 1

Input
server = [1, -1, -1, 1]
Output
1
Explanation

The first request consumes the only available thread. The second request arrives when the pool is empty, so it is dropped.

Constraints

Limits and guarantees your solution can rely on.

  • 1 <= n <= 10^5
  • server[i] = -1 or 1 <= server[i] <= 10^4
public int countDroppedRequests(int[] server) {
  // write your code here
}
Input

server

[1, -1, -1, 1]

Output

1

Sign in to submit your solution.