A turnstile writes each admitted badge number to a singly linked chain, and the chain is already sorted in non-decreasing order. Collapse runs of equal values so that each distinct value appears exactly once, preserving the ascending order, and print the resulting chain.
Line 1: an integer n, the number of nodes.
Line 2: n space-separated integers in non-decreasing order (empty line when n is 0).
Line 1: the number of nodes remaining after deduplication. Line 2: the remaining values in ascending order, space-separated (empty line if none).
Example 1
Input
6 1 1 2 3 3 3
Expected
3 1 2 3
Explanation
Collapsing each run of equal values leaves one of each: 1 2 3.
Example 2
Input
4 5 6 7 8
Expected
4 5 6 7 8
Explanation
All values are already distinct, so the chain is unchanged: 5 6 7 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 →