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
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Two Sum in Sorted ArrayEasy · java, python, c, cpp, javascriptSolve Problem
- Maximum Sum of K Consecutive ElementsEasy · java, python, c, cpp, javascriptSolve Problem
- First Negative Number in Every WindowMedium · java, python, c, cpp, javascriptSolve Problem