#K64907. Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array
Given a sorted array \(nums\) of size \(n\) in non-decreasing order, remove duplicates in-place so that each unique element appears only once. The relative order of the elements must be preserved. After removing duplicates, the first \(k\) elements of the array should contain the unique elements, where \(k\) is the number of unique elements.
You are required to read the input from stdin and output the result to stdout.
Note: Your solution must have an in-place algorithm with \(O(1)\) extra memory.
inputFormat
The input is given via stdin and has the following format:
- The first line contains a single integer \(n\) representing the number of elements in the array.
- The second line contains \(n\) integers separated by spaces in non-decreasing order.
outputFormat
Output to stdout in the following format:
- The first line should contain the integer \(k\), the number of unique elements.
- The second line should contain the first \(k\) unique elements of the modified array separated by a single space.
3
1 1 2
2
1 2
</p>