#K80867. Contains Nearby Duplicate
Contains Nearby Duplicate
Contains Nearby Duplicate
Given an array of integers and an integer k, determine whether there exist two distinct indices i and j in the array such that array[i] = array[j] and |i - j| ≤ k.
In mathematical terms, you are to check if there exist indices i and j with i ≠ j such that:
\[ |i - j| \leq k \quad \text{and} \quad a_i = a_j \]
If such indices exist, output TRUE; otherwise output FALSE.
Note: The input is provided via standard input (stdin) and the output should be printed to standard output (stdout). The first line of input contains an integer n representing the number of elements in the array. The second line contains n space-separated integers. The third line contains the integer k.
inputFormat
The first line of input contains an integer n (0 ≤ n ≤ 105), denoting the number of elements in the array.
The second line contains n space-separated integers representing the array elements. (If n = 0, this line will be empty.)
The third line contains an integer k (k ≥ 0), which represents the maximum allowed index distance.
outputFormat
Print a single line containing either TRUE if there exists two distinct indices i and j such that array[i] = array[j] and |i - j| ≤ k, or FALSE otherwise.
## sample6
1 2 3 1 2 3
2
FALSE
</p>