Hash maps and counting

Return the first label seen a second time, or "None" if all labels are unique.

Examples

Example 1

Input
["A", "B", "B", "A"]
Expected output
B

Example 2

Input
["A", "B", "C"]
Expected output
None

Hints and solution

Hint 1

A set of labels you have seen is enough to detect the first repeat.

Reveal worked answer

Process labels from left to right. If the current label is already present, return it immediately. Otherwise add it and keep scanning.

Back to the lesson