← 返回 snapchat 的题目列表Count events in a time window with unsorted duplicate timestamps
类型:online_judge
You are given a list of event timestamps timestamps (unsorted, duplicates allowed). Implement a query(start, end) method that returns how many events occurred within the time window [start, end] (inclusive).
Timestamp format: HH:MM:SS (e.g., "12:00:01").
Duplicate timestamps mean multiple events happened at the same second.
query will be called many times.
Example
timestamps = ["12:00:01", "01:02:02", "03:03:03"]
query("01:02:01", "01:02:03") => 1
query("01:00:00", "04:00:00") => 2
Assumed constraints
1 <= len(timestamps) <= 2*10^5
1 <= Q <= 2*10^5
Goal: make each query fast (e.g., O(log N)).
Example
Input
timestamps=["12:00:01","01:02:02","03:03:03"]; query("01:02:01","01:02:03")
Output
1