A vault inventory scans a pile of tags. Every distinct tag value was scanned exactly three times, except for a single lone tag that was scanned exactly once. Given all the scanned values in arbitrary order, identify the value of the lone tag.
Line 1: an integer n, the number of scans (n is congruent to 1 modulo 3).
Line 2: n space-separated non-negative integers, the scanned values.
A single integer: the value that appears exactly once.
Example 1
Input
4 5 5 5 9
Expected
9
Explanation
5 appears three times; 9 appears once, so the lone tag is 9.
Example 2
Input
7 2 4 2 8 4 2 4
Expected
8
Explanation
2 and 4 each appear three times; 8 appears once, so the answer is 8.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →