#C10720. Nearby Duplicate Elements

    ID: 39957 Type: Default 1000ms 256MiB

Nearby Duplicate Elements

Nearby Duplicate Elements

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

$$ a[i] = a[j] \quad \text{and} \quad |i - j| \le k. $$

This problem tests your ability to efficiently search for duplicate elements within a limited index range using appropriate data structures.

inputFormat

The input is provided via standard input and consists of three lines:

  • The first line contains an integer n, representing the number of elements in the array.
  • The second line contains n integers separated by spaces, representing the array elements.
  • The third line contains an integer k, representing the maximum allowed index difference.

outputFormat

Output a single line to standard output: "True" if there exists a pair of distinct indices i and j satisfying a[i] == a[j] and |i - j| \le k. Otherwise, output "False".

## sample
6
1 2 3 1 2 3
2
False