Count Repeated Request IDs (Data Science OA)
Updated
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) → intExamples
Example 1
requestIDs = ["authreq001", "authreq002", "authreq001", "authreq002"]timestamps = [10, 25, 20, 15]timeWindow = 10return = 2Summary of each unique request ID based on the time window condition:
"authreq001"appears at10and20. Since20 - 10 = 10 <= 10, it satisfies the condition."authreq002"appears at15and25. Since25 - 15 = 10 <= 10, it satisfies the condition.
Hence, the answer is 2.
Constraints
1 <= n <= 2 * 10^51 <= length of requestIDs[i] <= 2 * 10^5, and the sum of their lengths over allidoes not exceed2 * 10^5.1 <= timestamps[i], timeWindow <= 10^9
More McKinsey & Company Online Assessment questions
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