← 返回 amazon 的题目列表Detect duplicates / near-duplicates in streaming events
类型:online_judge
Given a stream of integer event IDs in arrival order, determine whether any duplicate ID appears within any sliding window of size k.
Input:
Line 1: n k
Line 2: n integers, the ID sequence
Output:
Print true if there exists a window where a duplicate occurs within distance k; otherwise print false.
Constraints:
1 <= n <= 2e5
0 <= k <= 2e5
IDs are 32-bit signed ints
Examples:
5 3 / 1 2 3 1 5 -> true
5 2 / 1 2 3 1 5 -> false
4 0 / 1 1 1 1 -> false
1 1 / 7 -> false
6 3 / 1 2 3 4 5 6 -> false
Example
Input
5 3
1 2 3 1 5
Output
true