#C4733. Contains Nearby Duplicate
Contains Nearby Duplicate
Contains Nearby Duplicate
You are given an array of integers and an integer k. Your task is to determine if there exist two distinct indices i and j in the array such that:
\(|i - j| \le k\) and \(nums[i] = nums[j]\).
If such a pair exists, print True
; otherwise, print False
.
Note: The indices are 0-based.
inputFormat
The input is given via stdin as follows:
- An integer n representing the number of elements in the array.
- A line with n space-separated integers representing the elements of the array nums.
- An integer k on a new line, representing the maximum allowed index difference.
outputFormat
Print a single line to stdout: True
if there exists at least one pair of duplicate numbers satisfying the condition, otherwise False
.
4
1 2 3 1
3
True