A database connection remains occupied while its request runs. When the pool is full, callers wait in arrival order, but a caller whose wait exceeds the configured timeout gives up without consuming a connection.
Design a ConnectionPoolScheduler class:
ConnectionPoolScheduler() creates a stateless scheduler.int[] startTimes(int[] arrivals, int[] durations, int poolSize, int waitTimeout) returns the start time of every request, or -1 when that request times out.
Requests are supplied in nondecreasing arrival order and are processed first-come, first-served. A connection that starts a request at time t for duration d becomes free at t + d. A request may wait at most waitTimeout; waiting exactly that long is allowed. Timed-out requests do not occupy a connection.
Example 1:
Input:
Output:
Explanation: Two connections serve the first requests immediately. The third waits from 1 to 3, and the final request begins at its arrival time 5.
Example 2:
Input:
Output:
Explanation: The only connection is unavailable until time 10, beyond both later requests' deadlines.
Constraints
0 <= arrivals.length == durations.length <= 10^50 <= arrivals[i] <= 10^9, in nondecreasing order.1 <= durations[i] <= 10^61 <= poolSize <= 10^50 <= waitTimeout <= 10^9- Every computed finish time fits in a signed 32-bit integer.