Bad Request Alerts
Updated
Problem statement
A service receives requests one at a time. Each entry requests[i] = [time, status] describes request i: time is when it arrived, in whole seconds, and status is 1 for a bad request or 0 for a good one. Requests are given in arrival order, so the times never decrease.
The service sends an alert right after request i when either rule holds, looking only at requests that came after the most recent alert:
- Streak rule: requests
i - 2,i - 1andiare all bad. - Window rule: request
iis bad, and at least3bad requests (counting requesti) have a time greater thanrequests[i][0] - 5. In other words, three bad requests arrived less than 5 seconds apart from first to last.
After an alert, the service forgets every request so far and starts counting again from the next request.
Return the indices of the requests that trigger an alert, in increasing order. If no alert is sent, return an empty list.
Function
findAlertIndices(requests: int[][]) → List<Integer>Examples
Example 1
requests = [[1,1],[2,1],[30,1],[31,0],[40,1]]return = [2]Requests 0, 1 and 2 are all bad, so the streak rule fires at index 2, even though request 2 came much later. After that alert the count starts over: request 3 is good and request 4 is the only bad request since, so no more alerts. The answer is [2].
Example 2
requests = [[0,1],[2,0],[4,1],[6,0],[7,1],[20,1]]return = []No three bad requests are in a row. At index 4 (time 7), the bad requests so far are at times 0, 4 and 7, but time 0 is not greater than 7 - 5 = 2, so only two of them count. At index 5 (time 20), the earlier bad requests are too old, and only indices 4 and 5 are bad in a row. No alert is sent, so the answer is [].
Example 3
requests = [[0,1],[1,1],[2,1],[3,1],[4,1],[5,1],[6,1]]return = [2,5]Indices 0, 1 and 2 are bad, so an alert fires at 2 and everything is forgotten. Counting starts again at index 3, so the next three bad requests trigger an alert at 5. Index 6 is only the first bad request of a new count. The answer is [2, 5].
Constraints
1 <= requests.length <= 5000requests[i].length == 20 <= requests[i][0] <= 10^9requests[i][1]is0or1requests[i][0] <= requests[i + 1][0]
More Microsoft Onsite Interview questions
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
- Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Fixed-Window Rolling MeanJump Trading · ONSITE INTERVIEWJump Trading interview questions
- Sliding Window Average (Meta Canada, E4/E5 :)Meta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Longest Subarray Within an Absolute-Difference LimitGoogle · ONSITE INTERVIEWGoogle interview questions
- Longest Continuous Subarray Within an Absolute-Difference LimitUber · ONSITE INTERVIEWUber interview questions
- Sliding-Window Rate LimiterSnowflake · ONSITE INTERVIEWSnowflake interview questions
- Sliding Window MaximumAmazon · ONSITE INTERVIEW
- Sliding Window MaximumPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Sliding Window MaximumBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Moving Average of a Data StreamSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Incident MonitorStripe · OAStripe interview questions
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)