Problem · Array

Count Dropped Requests

EasyJPMorgan ChaseFULLTIMEOA

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.

Examples
01 · Example 1
server = [1, -1, -1, 1]
return = 1

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

Constraints
  • 1 <= n <= 10^5
  • server[i] = -1 or 1 <= server[i] <= 10^4
More JPMorgan Chase problems
drafts saved locally
public int countDroppedRequests(int[] server) {
  // write your code here
}
server[1, -1, -1, 1]
expected1
sign in to submit