What is the problem with the code?
n = int(input())
l = [int(i) for i in input().split()]
k = int(input())
def duplicate(l, k):
d = {}
for i in range(len(l)):
if l[i] not in d.keys():
d[l[i]] = i
else:
dist = i - d[l[i]]
d[l[i]] = dist
if (dist<=k):
print("true")
return
print("false")
duplicate(l, k)
I’m getting wrong answer for most of the test cases