Reported July 2026
IBMsliding window

Maximum Requests in a Time Window

Reported by candidates from IBM's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live IBM OA. Under 2s to a working solution.
Founder's read

The constraint that matters in this IBM OA question, reported in July 2026, is n up to 2 * 10^5 with timestamps up to 10^9. That kills any idea of trying every window start x or checking every pair. You've got a sorted array and a window width, and you need the densest cluster. It's a sliding window problem wearing a rate-limiter costume. If you blank when the clock is running, StealthCoder sits invisibly on your screen as a safety net and hands you the approach. But the logic here is short enough that you can own it before the invite even opens.

The problem

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 window
int 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[]) → int

Examples
Example 1
window = 5
timestamps = [1, 2, 3, 8, 10]
return = 3
The 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^9
1 <= n <= 2 * 10^5
0 <= timestamps[i] <= 10^9
It is guaranteed that timestamps are sorted in non-decreasing order.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Timestamps are already sorted, so use two pointers. Move the right pointer across the array. While timestamps[right] - timestamps[left] >= window, advance left. The window size is right - left + 1, and you track the max. That's O(n) time and O(1) space. The trick is the closed interval [x, x + window - 1]. A window of size 5 covers 5 integer values, so the condition to shrink is difference >= window, not > window. That off-by-one is the classic pitfall. Don't iterate over x values, since the range goes up to 10^9. Anchoring the window on an actual timestamp is enough, because the best window can always slide right until its left edge hits a request. Duplicates are fine with this approach. If the live OA freezes you on the boundary condition, StealthCoder is the hedge, but test your example by hand first.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Maximum Requests in a Time Window cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass IBM's OA.

IBM reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Requests in a Time Window FAQ

What's the trick to Maximum Requests in a Time Window?+

Sliding window on the sorted array. Push the right pointer forward, and move the left pointer while timestamps[right] - timestamps[left] >= window. Track the largest right - left + 1. The best window can always be anchored at a real timestamp, so you never need to iterate over x.

Why doesn't brute force work here?+

Timestamps go up to 10^9, so trying every start x is far too slow. Checking every pair or recounting per start is O(n^2) on 2 * 10^5 elements, which also times out. The sorted input is the hint that a linear two-pointer pass is expected.

What's the most common bug on this problem?+

The off-by-one on the closed interval. The window [x, x + window - 1] holds exactly window integer values. So two timestamps fit together only if their difference is at most window - 1. Shrink when the difference is >= window. Test with window = 5 and timestamps 1 and 5.

Do I need to sort the timestamps?+

No. The problem guarantees they're sorted in non-decreasing order. Skipping the sort keeps you at O(n). Duplicate timestamps are allowed and count as separate requests, and the two-pointer approach handles them without special cases.

How do I prepare for this in 48 hours?+

Write the two-pointer loop from scratch three times, then run Example 1 by hand: window 5, timestamps [1, 2, 3, 8, 10], answer 3. Add edge cases like n = 1, all equal timestamps, and window = 1. That covers nearly everything this question can throw at you.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with IBM.

OA at IBM?
Invisible during screen share
Get it