#K37912. Nearby Duplicate Detection

    ID: 26082 Type: Default 1000ms 256MiB

Nearby Duplicate Detection

Nearby Duplicate Detection

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 the elements at these indices are equal (nums[i] = nums[j]) and the absolute difference between i and j is at most k (i.e. |i - j| \le k).

Input Format: The first line contains two integers n and k, where n is the number of elements in the array. The second line contains n space-separated integers representing the array.

Output Format: Print True if there exists at least one pair of duplicate elements satisfying the condition, otherwise print False.

Note: If the array is empty (n = 0), output False.

inputFormat

The input is given via standard input (stdin). The first line contains two integers n and k. The second line contains n space-separated integers.

outputFormat

Output a single line to standard output (stdout): print True if there exists a pair of indices i and j such that nums[i] == nums[j] and |i - j| \le k; otherwise, print False.## sample

4 3
1 2 3 1
True