A radio station logs its playback queue as the sequence of track IDs in the exact order they were added, before any track has actually played. The same numeric ID can be queued more than once if a listener requests the same track multiple times, and these repeats can land anywhere in the sequence, not necessarily next to each other. Before broadcasting, the producer wants every track whose ID appears more than once anywhere in the logged sequence removed entirely -- every occurrence of that ID, not just the later ones -- leaving only the tracks that were queued exactly once, still in their original relative order.
n, the number of entries in the queue.n space-separated integers, the track IDs in queued order.k, the number of tracks that remain after the purge.k remaining track IDs, space-separated, in their original relative order (print an empty line if k is 0).1 <= n <= 1000000 <= track ID <= 100000Example 1
Input
8 7 3 4 3 7 5 6 5
Expected
2 4 6
Explanation
Track 7 appears twice (indices 0 and 4), track 3 appears twice (indices 1 and 3), track 5 appears twice (indices 5 and 7); only track 4 (index 2) and track 6 (index 6) appear exactly once, so they survive in their original order, giving `4 6`.
Example 2
Input
6 1 2 1 2 1 2
Expected
0
Explanation
Track 1 appears three times and track 2 appears three times, so both IDs are entirely removed; no track survives, so the output is `0` followed by an empty line.
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 →