Loading...
Loading...
Groww's backend receives thousands of concurrent user requests every second — from stock price lookups to order placements. Unlike a single process (which has its own memory space and runs independently), threads share the same process memory and can handle tasks concurrently within that process. To efficiently serve users, Groww's backend uses a thread pool where each thread handles one request at a time.
You are given a list of user requests, each defined by their arrival time and processing duration (in milliseconds). Your task is to determine the minimum number of threads needed so that no request ever has to wait — every request is immediately picked up by an available thread upon arrival.
Given n requests with their arrival times and processing durations, find the minimum number of threads required to handle all requests without any request waiting.
n — number of requestsrequests of size n x 2 where:
requests[i][0] = arrival time of the i-th request (in ms)requests[i][1] = processing duration of the i-th request (in ms)Return a single integer — the minimum number of threads needed.
Input: requests = [[0,5],[2,3],[4,2],[8,1]]
Output: 2
Explanation:
Input: requests = [[0,10],[0,10],[0,10]]
Output: 3
Explanation: All 3 requests arrive simultaneously at t=0. Each needs its own thread since no thread is free. Minimum threads = 3.
Input: requests = [[0,2],[3,2],[6,2]]
Output: 1
Explanation: Requests arrive sequentially and each finishes before the next arrives. A single thread handles all requests one by one.
1 <= n <= 10^5 0 <= requests[i][0] <= 10^9 1 <= requests[i][1] <= 10^4 Requests are not necessarily sorted by arrival time
This mirrors exactly how OS process schedulers and thread pools work in systems like Groww's backend!