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
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution