Problem · Greedy
Rate-Limiting Algorithm
Learn this problemProblem statement
Some developers at Amazon are building a prototype for a simple rate-limiting algorithm. There are n requests to be processed by the server, represented by a string requests, where the i-th character represents the region of the i-th client. Each request takes 1 unit of time to process.
There must be a minimum time gap of minGap units between any two requests from the same region.
Function
getMinTime2(n: int, requests: String, minGap: int) → int
Complete the function getMinTime in the editor.
getMinTime has the following parameters:
n: int: the number of requestsrequests: String: a string representing the region of each requestminGap: int: the minimum time gap required between requests from the same region
Returns
The function should return an integer representing the minimum time required to process all requests without denial.
Examples
Example 1
n = 6requests = "aaabbb"minGap = 2return = 8
The requests can be sent in the order ab_ab_ab where _ represents that no request was sent in that unit time. Here, the minimum time gap between two requests from the same region is minGap = 2.
The total time taken is 8 units.
Example 2
n = 12requests = "abacadaeafag"minGap = 2return = 16One optimal strategy is "ab_ad_afgae_ac_a
Constraints
1 <= length of requests <= 1050 <= minGap <= 100It is guaranteed that requests contain lowercase English charactersMore Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026