classSolution: defcontainsNearbyDuplicate(self, nums: List[int], k: int) -> bool: k += 1 table = set() f = False g = min(k, len(nums)) for i inrange(g): if nums[i] in table: f = True break table.add(nums[i]) if f: returnTrue for i inrange(g, len(nums)): table.remove(nums[i - k]) if nums[i] in table: f = True break table.add(nums[i]) return f