Count Dropped Rate-Limited Requests
Updated
Problem statement
You are given a nondecreasing array requestTimes, where each value is the integer second when one request arrives. Process requests in array order. A request is dropped if accepting it would exceed any of these limits:
- At most
3requests in one second. - At most
20requests in any rolling10-second interval. - At most
60requests in any rolling60-second interval.
For a request at second t, the rolling intervals are [t - 9, t] and [t - 59, t], respectively. Dropped requests still count when evaluating every later limit. If multiple limits reject the same request, count that request only once.
Return the total number of dropped requests.
Function
countDroppedRequests(requestTimes: int[]) → intExamples
Example 1
requestTimes = [1,1,1,1]return = 1The fourth request at second 1 exceeds the three-per-second limit.
Example 2
requestTimes = [1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7]return = 1The first twenty requests fit in the rolling ten-second interval. The twenty-first request is dropped.
Example 3
requestTimes = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,60]return = 1The final request is the sixty-first request in the interval from second 1 through second 60, so it is dropped by the sixty-second limit.
Constraints
0 <= requestTimes.length <= 2000001 <= requestTimes[i] <= 1000000000requestTimesis sorted in nondecreasing order.
More Oracle Onsite Interview questions
- Course ScheduleONSITE INTERVIEW · Seen Nov 2026
- Shortest Subarray with Sum at Least KONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Minimum Meeting RoomsONSITE INTERVIEW · Seen Nov 2026
- Shortest Window with Required CountsONSITE INTERVIEW · Seen Nov 2026
- Maximum Subarray Sum with One DeletionONSITE INTERVIEW · Seen Nov 2026
- Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
- Design Authentication ManagerONSITE INTERVIEW · Seen Oct 2026
- Maximum Bouquet ValueONSITE INTERVIEW · Seen Oct 2026
- Cache an Expensive Service Across ThreadsONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Maximum Earnings Across WarehousesAmazon · ONSITE INTERVIEW
- Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Longest Subarray Within an Absolute-Difference LimitGoogle · ONSITE INTERVIEWGoogle interview questions
- Longest Binary Subarray With at Most K OnesLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Max Consecutive Ones IIIMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Longest Continuous Subarray Within an Absolute-Difference LimitUber · ONSITE INTERVIEWUber interview questions
- Sliding-Window Rate LimiterSnowflake · ONSITE INTERVIEWSnowflake interview questions
- Count Equal Code Pairs Within Distance KInfosys · ONSITE INTERVIEWInfosys interview questions
- Maximize Element FrequencyGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Longest Subarray with At Most Two Distinct ValuesMoody's Investors Service · ONSITE INTERVIEW