Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
def containsNearbyDuplicate(nums, k):
index_map = {}
for i in range(len(nums)):
if nums[i] in index_map:
if i - index_map[nums[i]] > k:
index_map[nums[i]] = i
else:
return True
else:
index_map[nums[i]] = i
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment