#K48142. Contains Nearby Duplicate
Contains Nearby Duplicate
Contains Nearby Duplicate
You are given an array of integers nums and an integer k. Your task is to determine whether there exist two distinct indices i and j in the array such that:
\( nums[i] = nums[j] \quad \text{and} \quad |i - j| \le k \)
If such a pair exists, output True
; otherwise, output False
.
Note: The array indices are considered in a 0-based manner.
inputFormat
The input is given via standard input in the following format:
- An integer n denoting the number of elements in the array.
- A line with n integers separated by spaces, representing the elements of the array nums.
- An integer k representing the maximum allowed index difference.
outputFormat
Output a single line to the standard output: True
if there exists a duplicate number such that the indices difference is at most k, otherwise False
.
4
1 2 3 1
3
True
</p>