FastPrepCount Repeated Request IDs (Data Science OA)
Problems/Count Repeated Request IDs (Data Science OA)

Count Repeated Request IDs (Data Science OA)

McKinsey & Company logoMcKinsey & Company● EasyFULLTIMENEW GRADOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

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 = 10return = 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

More McKinsey & Company Online Assessment questions

  • Minimize Adjacent Squared-Difference Cost with One InsertionOA · Seen Oct 2026
  • Weekend Appointments for Consular Services ReschedulingOA · Seen Oct 2026
  • Minimum Knight MovesOA · Seen Jun 2026

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
  • Flat JSON Value DifferencesChubb · OAChubb interview questions
  • Get Search ResultsJP Morgan Chase · OAJP Morgan Chase interview questions
  • Lexicographic Word FrequenciesUpstart · OAUpstart interview questions
  • Email Log Processing, Grouping, and SortingStripe · OAStripe interview questions
  • Most Frequent CharacterMicrosoft · OAMicrosoft interview questions
  • Get Maximum Information GainAmazon · OA
  • Better CompressionGoldman Sachs · OAGoldman Sachs interview questions
  • Process LogsSnowflake · OASnowflake interview questions
All McKinsey & Company interview questionsSee McKinsey & Company hiring insights
Saved
class Solution {
    public int countRepeatedRequestIds(String[] requestIDs, int[] timestamps, int timeWindow) {
      // write your code here
    }
}
Checking account…