#C2736. Contains Nearby Almost Duplicate
Contains Nearby Almost Duplicate
Contains Nearby Almost Duplicate
You are given an array of integers and two integers (k) and (t). The task is to determine if there exist two distinct indices (i) and (j) in the array such that
[ |nums[i] - nums[j]| \leq t \quad \text{and} \quad |i - j| \leq k ]
If such a pair exists, output “True”; otherwise, output “False”. This problem requires efficient handling of range queries under a sliding window constraint.
inputFormat
The input is given via standard input in the following format:
- The first line contains an integer (n), the number of elements in the array.
- The second line contains (n) space-separated integers representing the elements of the array.
- The third line contains two space-separated integers, (k) and (t).
outputFormat
Print a single line to standard output. Output “True” if there exists a pair of indices (i, j) satisfying the conditions; otherwise, output “False”.## sample
4
1 2 3 1
3 0
True