Problem · Array
Count Dropped Requests
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.
-1means 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^5server[i] = -1or1 <= server[i] <= 10^4
More JPMorgan Chase problems
public int countDroppedRequests(int[] server) {
// write your code here
}
server[1, -1, -1, 1]
expected1
sign in to submit