Skip to content
CampusEduX

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).

Related Problems

  • Two Sum in Sorted Array
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • Maximum Sum of K Consecutive Elements
    Easy · java, python, c, cpp, javascript
    Solve Problem
  • First Negative Number in Every Window
    Medium · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...