#K89232. Contains Nearby Almost Duplicate

    ID: 37485 Type: Default 1000ms 256MiB

Contains Nearby Almost Duplicate

Contains Nearby Almost Duplicate

You are given an integer array arr and an integer k. Your task is to determine whether there exist two distinct indices i and j in the array such that:

  • The absolute difference between the array values satisfies \[ |arr[i] - arr[j]| \le k, \] and
  • The absolute difference between the indices satisfies \[ |i - j| \le k. \]

If such a pair exists, output True, otherwise output False.

Note: The input is read from standard input and the output is printed to standard output.

inputFormat

The first line contains two integers n and k, where n is the number of elements in the array and k is the integer parameter used for both the value and index difference constraints.

The second line contains n space-separated integers representing the array arr. If n is 0, the second line will be empty.

outputFormat

Output a single line: True if there exists at least one pair of indices i and j satisfying |arr[i] - arr[j]| ≤ k and |i - j| ≤ k, otherwise output False.

## sample
4 3
1 2 3 1
True

</p>