You get an array of integers nums and a number k.
Is there a pair of different positions i and j that hold the same number (nums[i] == nums[j]) and are at most k places apart (abs(i - j) <= k)?
Return true if there is such a pair, and false if there is not.
Examples
Example 1:
Input: nums = [5,1,6,5], k = 3
Output: true
Explanation: The two 5s are at positions 0 and 3. The distance is 3, which is at most 3.
Example 2:
Input: nums = [5,1,6,5], k = 2
Output: false
Explanation: The two 5s are 3 positions apart, which is more than 2.
Example 3:
Input: nums = [2,2], k = 1
Output: true
Explanation: The two 2s are next to each other.