#K12956. Nearby Duplicate Checker
Nearby Duplicate Checker
Nearby Duplicate Checker
You are given an array of integers nums and an integer k. Your task is to determine whether there exists two distinct indices \(i\) and \(j\) in the array such that:
\(nums[i] = nums[j]\) and \(|i - j| \le k\)
If such a pair exists, output True
, otherwise output False
.
Note: The condition \(|i - j| \le k\) means that the absolute difference between the indices is at most \(k\).
inputFormat
The input is given in two lines:
- The first line contains two space-separated integers
n
andk
, wheren
is the number of elements in the array. - The second line contains
n
space-separated integers representing the arraynums
.
outputFormat
Output a single line with True
if there exists a pair of indices satisfying the conditions, otherwise output False
.
4 3
1 2 3 1
True