Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def firstDupe(a):
- """
- Finding the first occurrence of any duplicates with the first second occurrence of a value
- as long as params are met.
- Returns -1 if outside params.
- """
- if len(a) == len(set(a)):
- return -1
- indices = [a.index(i) for i in a]
- ilist = list()
- if 1 <= len(a) <= 10 ** 5: # param 1
- for i in range(0, len(a)):
- if indices[i] <= len(a): # param 2
- if indices[i] != i:
- ilist.append((i, a[i])) # ilist appends the second index occurrence
- # of the dupe value
- else:
- return -1
- else:
- return -1
- #print(ilist)
- if len(ilist) == 0:
- return -1
- n = [(z, x) for z, x in ilist]
- print(n, min(n)[1])
- return min(n)[1]
- firstDupe([6, 8, 4, 9, 1, 4, 12, 5, 3, 5, 10, 12])
Add Comment
Please, Sign In to add comment