Reported June 2026
McKinseyhash table

Count Repeated Request IDs

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

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

The McKinsey OA reported in June 2026 has a problem called Count Repeated Request IDs, and it looks fancier than it is. Strip the request-log story and it's a group-by-key problem with a sort and an adjacent-gap check. If you've got an invite for the next couple of days, this is the shape to expect. Group timestamps by ID, sort each group, check neighbors. That's the whole thing. If your brain freezes mid-assessment, StealthCoder runs invisibly on your desktop and can hand you the solution as a safety net.

The problem

Arrays requestIDs and timestamps are given, along with an integer timeWindow.
requestIDs[i] represents the ID of a request.
timestamps[i] represents the time, in seconds, when that request occurred.
A request ID is considered repeated within the window if:
it appears at least twice, and
there exist two occurrences whose time difference is less than or equal to timeWindow.
Your task is to count how many distinct request IDs satisfy this condition.
Return the count.

Function
countRepeatedRequestIds(requestIDs: String[], timestamps: int[], timeWindow: int) → int

Examples
Example 1
requestIDs = ["authreq001", "authreq002", "authreq001", "authreq002"]
timestamps = [10, 25, 20, 15]
timeWindow = 10
return = 2
Summary of each unique request ID based on the time window condition:
"authreq001" appears at 10 and 20. Since 20 - 10 = 10 <= 10, it satisfies the condition.
"authreq002" appears at 15 and 25. Since 25 - 15 = 10 <= 10, it satisfies the condition.
Hence, the answer is 2.

Constraints
1 <= n <= 2 * 10^5
1 <= length of requestIDs[i] <= 2 * 10^5, and the sum of their lengths over all i does not exceed 2 * 10^5.
1 <= timestamps[i], timeWindow <= 10^9

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: if any two occurrences of an ID are within timeWindow, then some adjacent pair in sorted order is too. So you never compare all pairs. Build a hash map from ID to a list of timestamps, sort each list, and scan for any consecutive difference <= timeWindow. Count the IDs where that happens. Total cost is O(n log n) because of sorting. The pitfall is that the timestamps array is NOT sorted (the example has 25 before 15 for authreq002), so skipping the sort gives wrong answers. Another trap is the quadratic pairwise check, which dies at n up to 2 * 10^5. Also remember the condition is less than or equal, not strict. Count each ID once, so break out of the scan as soon as one pair qualifies. If you blank during the live OA, StealthCoder is the hedge that gets you the map-plus-sort skeleton fast.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Count Repeated Request IDs 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder
⏵ The honest play

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

McKinsey reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Repeated Request IDs FAQ

What's the trick in Count Repeated Request IDs?+

Only adjacent timestamps matter after sorting. If any two occurrences of an ID fall within timeWindow, the closest pair does, and the closest pair is always neighbors in sorted order. Group by ID, sort, check consecutive gaps. No pairwise comparison needed.

How hard is this McKinsey OA question really?+

Easy to medium. There's no fancy data structure. A hash map and a sort cover it. The difficulty is noticing the timestamps are unsorted and avoiding an O(n^2) approach given n up to 2 * 10^5.

What time complexity should I aim for?+

O(n log n) overall. Building the map is linear, and sorting each ID's timestamps totals at most n log n. A nested loop over occurrences would time out on the largest inputs, so don't submit it.

Is the difference check strict or inclusive?+

Inclusive. The problem says less than or equal to timeWindow. In the example, 20 - 10 = 10 with a window of 10 counts as repeated. Using strict less-than would return 0 instead of 2 on the sample.

How do I prepare for this in 48 hours?+

Write the solution once from scratch: map of ID to list, sort, scan neighbors, count. Then test the sample plus an ID that appears once and one with timestamps out of order. Also practice a sliding-window variant of the same idea. That covers the likely twists.

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

OA at McKinsey?
Invisible during screen share
Get it