Problem · Hash Table
Count Repeated Request IDs
Learn this problemProblem 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