← 返回 bloomberg 的题目列表Detect Duplicate Items Within a 60-Second Sliding Window
类型:online_judge
Problem: Detect Duplicate Content Within a 60-Second Window
You are given a stream of content records sorted by non-decreasing timestamp. Each record has the following fields:
id, content, title, timestamp
Where:
id is a unique string identifier;
content is the text body;
title is the title;
timestamp is an integer arrival time in seconds.
Two records are considered duplicates if both their content and title are the same, and their timestamps differ by at most 60 seconds.
Find all records that are duplicates at arrival time. For each duplicate record, output the pair consisting of the earliest previous matching record still inside the 60-second window and the current record.
To optimize memory usage, records older than 60 seconds relative to the current timestamp should be removed from the tracking structure.
Input Format
The first line contains an integer n, the number of records.
The next n lines each have the format:
id, content, title, timestamp
Fields are separated by commas. Extra spaces around fields may appear.
Output Format
For each detected duplicate pair, print one line:
old_id,new_id
Where:
old_id is the earliest previous record with the same (content, title) inside the current 60-second window;
new_id is the current duplicate record.
If no duplicate exists, print:
NONE
Constraints
1 <= n <= 200000
0 <= timestamp <= 10^9
Records are sorted by non-decreasing timestamp
Length of id, content, and title is at most 100
Example
Input:
4
id1, t1, title1, 2
id2, t2, title2, 4
id3, t1, title1, 50
id4, t1, title1, 80
Output:
id1,id3
id3,id4
Explanation:
id3 duplicates id1, because they have the same (content, title) and 50 - 2 = 48 <= 60;
id4 duplicates id3, because they have the same (content, title) and 80 - 50 = 30 <= 60.
Example
Input
4
id1, t1, title1, 2
id2, t2, title2, 4
id3, t1, title1, 50
id4, t1, title1, 80
Output
id1,id3
id3,id4