A weather station stores its temperature readings, one per node, as a singly linked list sorted in non-decreasing order. Because the sensor sometimes re-reports the same value on consecutive ticks, the same reading may appear in several consecutive nodes. Remove duplicate nodes so that each distinct value survives only once (keep the first node of each run of equal values). Print the resulting readings in order.
Line 1: an integer n — the number of readings.
Line 2: n space-separated integers, sorted in non-decreasing order — the readings.
The distinct-in-a-row readings, space-separated, in their original order.
Example 1
Input
6 1 1 2 3 3 3
Expected
1 2 3
Explanation
Runs are [1,1], [2], [3,3,3]; keeping the first of each gives 1 2 3.
Example 2
Input
1 5
Expected
5
Explanation
A single reading has no duplicates, so it is unchanged: 5.
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 →