A telemetry pipeline replays a stream of n integer event codes, some of which repeat. Produce a cleaned stream that keeps only the first occurrence of each event code, in the original order, discarding every later repeat.
Line 1: an integer n.
Line 2: n space-separated integers (the event codes, in the order they occurred).
The cleaned stream: the distinct event codes in order of first appearance, space-separated on a single line.
Example 1
Input
6 4 5 4 6 5 7
Expected
4 5 6 7
Explanation
4 and 5 each repeat later in the stream; only their first occurrence is kept, followed by the new codes 6 and 7.
Example 2
Input
3 1 1 1
Expected
1
Explanation
Only the first 1 is kept; the two later repeats are discarded.
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 →