#C4548. Contains Nearby Duplicate

    ID: 48098 Type: Default 1000ms 256MiB

Contains Nearby Duplicate

Contains Nearby Duplicate

Given an array of integers and an integer (k), determine if there exist two distinct indices (i) and (j) such that (nums[i] = nums[j]) and (|i - j| \leq k).

The solution should read input from standard input (stdin) and print the result to standard output (stdout).

inputFormat

The input consists of three lines:
1. The first line contains an integer (n), representing the number of elements in the array.
2. The second line contains (n) space-separated integers, the elements of the array.
3. The third line contains an integer (k), the maximum allowed index difference.

outputFormat

Output a single line containing (YES) if there exist two indices satisfying the condition; otherwise, output (NO).## sample

6
1 2 3 1 2 3
2
NO