Problem · Array
Count Dropped Requests
Learn this problemProblem statement
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.
Function
countDroppedRequests(server: int[]) → intExamples
Example 1
server = [1, -1, -1, 1]return = 1The 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