I need faster algorithm. Problem - to leave only the last occurrences of each element in the sequence; the remaining elements must be removed from the sequence. Thank you.
Given: 1 2 3 3 2 1 4 1 2 0
Answer:3 4 1 2 0
My algorithm:
k = input().split()
s=[]
for i in k:
if i not in s:
s.append(i)
else:
s.remove(i)
s.append(i)