An office door logs every badge scan of the day as a singly linked list of badge IDs, sorted in non-decreasing order (one node per scan). A badge ID that was scanned more than once indicates a scanner glitch. Remove ALL nodes carrying such an ID, keeping only the badge IDs that were scanned exactly once, in their original order. Print the resulting IDs (print an empty line if no ID was scanned exactly once).
Line 1: an integer n — the number of scans.
Line 2: n space-separated integers, sorted in non-decreasing order — the scanned badge IDs.
The badge IDs that appear exactly once, space-separated, in their original order (an empty line if none qualify).
Example 1
Input
5 1 1 2 3 3
Expected
2
Explanation
1 and 3 each appear twice and are fully removed; only 2 appears once, so the output is 2.
Example 2
Input
3 1 2 3
Expected
1 2 3
Explanation
No ID repeats, so all three survive: 1 2 3.
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 →