#C9282. Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array
Given a sorted array of integers, remove the duplicates in-place such that each element appears only once. The relative order of the elements must be preserved. After removal, the front part of the array should contain the unique elements in sorted order. Your task is to modify the array in-place with \(O(1)\) extra memory, and then output the new length followed by the unique elements.
inputFormat
The input is given from stdin in the following format:
- The first line contains an integer \(n\) representing the number of elements in the array.
- The second line contains \(n\) space-separated integers sorted in non-decreasing order.
outputFormat
Output to stdout in the following format:
- The first line contains the new length of the array after duplicates have been removed.
- The second line contains the unique elements separated by a single space. If the array is empty, only output the new length.
5
1 1 2 2 3
3
1 2 3
</p>