First repeated checkpoint
A route log lists checkpoint codes in travel order. Print the first code whose second visit occurs earliest. If the route never revisits a checkpoint, print NONE. This is about the first repeated event, not the alphabetically smallest repeated code.
Input
One line of space-separated checkpoint codes.
Output
The first code encountered for a second time, or NONE.
Example 1
Input
a b c b a
Output
b
The second b is encountered before the second a, so b wins even though a sorts first.
Constraints
- The route has 1 to 200 checkpoint codes.
- Codes are case-sensitive non-empty tokens.
Hints
Hint 1 of 2
A set answers whether a code has been visited.
Hint 2 of 2
Stop on the second visit; sorting loses event order.
Solution
Show a reference solution and explanation
seen = set()
answer = 'NONE'
for code in input().split():
if code in seen:
answer = code
break
seen.add(code)
print(answer)
Why it works
Scan checkpoints in order, remembering prior codes in a set. The first membership hit is exactly the earliest second visit. Breaking immediately prevents a later repeated code from replacing the correct answer; if no hit occurs, NONE remains.
Lesson for this exercise: Sets in Python