#C2445. Contains Nearby Duplicate
Contains Nearby Duplicate
Contains Nearby Duplicate
Given an array of integers and an integer (k), determine whether the array contains any duplicates such that the absolute difference between their indices is at most (k). In other words, if there exist two indices (i) and (j) with (i \neq j) for which ( |i - j| \le k ) and (arr[i] = arr[j]), then output "True"; otherwise, output "False".
For example, if the array is [1, 2, 3, 1, 5] and (k = 3), the output is "True" because the two occurrences of 1 are 3 indices apart.
inputFormat
Input is read from standard input (stdin). The first line contains two integers (N) and (k), where (N) is the number of elements in the array and (k) is the maximum allowed index difference. The second line contains (N) space-separated integers representing the array elements.
outputFormat
Output a single line to standard output (stdout) containing either "True" or "False". Output "True" if there exists at least one pair of duplicate elements within a distance of (k), otherwise output "False".## sample
5 3
1 2 3 1 5
True