A repeat within k positions
Given a list of integers nums and an integer k >= 0, return True if some value appears at two different positions i and j with abs(i - j) <= k, and False otherwise. Copies farther apart than k do not count.
nums may be empty and k may exceed its length. Aim for one pass that keeps at most k values in memory.
Besides the tests, one large input (10,000 distinct values) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
has_close_repeat([1,2,3,1], 3)→truehas_close_repeat([1,2,3,1], 2)→falsehas_close_repeat([7,3,7,3,7], 1)→false