Remove Duplicates Using Two Pointers
Easyjavapythonccppjavascript
Given a sorted array, remove duplicate values in-place using a two-pointer approach, and report the number of unique values and the unique values themselves.
Input Format
The first line contains an integer N. The second line contains N space-separated integers in non-decreasing order.
Output Format
Print two lines: Count = C Values = v1 v2 ... (the distinct values in increasing order, space-separated).
Example 1
Input
5 1 1 2 2 3
Output
Count = 3 Values = 1 2 3
Explanation: Three distinct values remain after removing duplicates.
- 1 <= N <= 100000
- The array is sorted in non-decreasing order.
- -1000000000 <= A[i] <= 1000000000