288. First Value That Repeats
Foundation1000 ms256 MBSolved by 0%
Print the first value that has been seen before, scanning left to right. If
no value repeats, print None.
1 2 3 2 1 -> 2
The answer is 2 rather than 1, because the SECOND 2 appears before the second 1. So this is the first value whose repeat occurs earliest, which is exactly what a single left-to-right pass finds.
Constraints - `1 ≤ n ≤ 200000` - `-1000000000 ≤ a[i] ≤ 1000000000`
Input
The first line contains an integer n.
The second line contains n integers.
Output
Print the first repeating value, or None if there is none.
Input5
1 2 3 2 1
Output2
Notehas two repeating values, and the one repeating EARLIEST wins
Input3
1 2 3
OutputNone
Notehas no repeats at all
Hints
Four rungs, in order. The last two open once you have submitted an attempt — a wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first — this one carries on from it.
Hint 3PseudocodeOpen hint 2 first — this one carries on from it.
Hint 4Full solutionOpen hint 3 first — this one carries on from it.