Maximum Requests in a Time Window
Updated
Problem statement
Given an array of timestamps and a window size, find the maximum number of requests made within any time window defined as the closed interval [x, x + window - 1] for some integer x.
The function maximumRequests will take two inputs:
int window: the size of the time windowint timestamps[n]: array of request timestamps
The function should return an integer denoting the maximum number of requests made within any given window size.
Function
maximumRequests(window: int, timestamps: int[]) → intExamples
Example 1
window = 5timestamps = [1, 2, 3, 8, 10]return = 3The window [0, 4] contains 3 requests at timestamps 1, 2, and 3, which is the maximum among all windows of size 5. Hence, the answer is 3.
Constraints
1 <= window <= 10^91 <= n <= 2 * 10^50 <= timestamps[i] <= 10^9- It is guaranteed that
timestampsare sorted in non-decreasing order.
More IBM Online Assessment questions
- Missing IntervalsOA · Seen Nov 2026
- Count Peaks and ValleysOA · Seen Nov 2026
- Last Object Exit TimeOA · Seen Nov 2026
- Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
- Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
- Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
- Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
- Tree Pythagorean TriplesOA · Seen Oct 2026
- Minimum Power-of-Two Removal OperationsOA · Seen Oct 2026
- Maximum Compatible Time WindowsOA · Seen Oct 2026
Similar questions at other companies
- Maximum Events in a 60-Second WindowMarshall Wace · OAMarshall Wace interview questions
- Count Subarrays With Product Equal to KSalesforce · OASalesforce interview questions
- Count Belt Sections With K Fruit Pairs (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- Fastest Average Speed over a Rolling KilometerOptiver · OAOptiver interview questions
- Maximum Consecutive Sum Within a ThresholdIndeed · OAIndeed interview questions
- Compact Conversation History by Token BudgetSierra · PHONE SCREENSierra interview questions
- Subarray Product Less Than KApple · PHONE SCREENApple interview questions
- Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
- Subarray Product Less Than KAngel One · PHONE SCREEN
- Subarray Product Less Than KThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions