54. Remove Duplicates from a Sorted Array
Core1000 ms256 MBSolved by 0%
The array is already sorted in non-decreasing order.
Print it with consecutive duplicates removed, keeping one of each value, separated by single spaces.
Do it in a single pass. Because the array is sorted, all copies of a value sit together, you never need to look further back than the previous element you kept.
Constraints - `1 ≤ n ≤ 200000` - `-1000000 ≤ a[i] ≤ 1000000` - The array is sorted.
Input
The first line contains an integer n.
The second line contains n space-separated integers.
Output
Print the remaining values in order on ONE line, separated by single spaces.
Input6
1 1 2 2 3 4
Output1 2 3 4
Notehas duplicates at the start
Input5
1 2 3 4 5
Output1 2 3 4 5
Notehas no duplicates, so nothing changes
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.