In a given list of integers, find the first element which is repeated. E.g., in the list (1, 3, 5, 5, 8, 3, 2, 5, 8, 3) the first repeated element is 3 (not 5).

Design and implement an algorithm for this problem, using appropriate data structures.

Assignment

Write a Python function firstDuplicate(numbers: list). This function takes a list of numbers as its argument and returns the first element that is repeated. If there is no such element, return None.

Examples

>>> firstDuplicate([1, 3, 5, 5, 8, 3, 2, 5, 8, 3])
3
>>> firstDuplicate([1, 3, 5, 5, 8, 6, 2, 5, 8, 3])
3
>>> firstDuplicate([208412, 4, 9, 7, 6, 5, 4, 8, 1, 87])
4
>>> firstDuplicate([369874, 4, 9, 7, 6, 5, 18, 8, 1, 87])