Remove Duplicates from Sorted Array

Easy · Two Pointers · Array · Two Pointers

Problem

nums is sorted ascending. Remove the duplicates in place so each value appears once, keeping the order, and return the number of unique values k.

Only the first k positions of nums are checked; whatever sits beyond them does not matter.

Examples

Input: nums = [1,1,2]
Output: 2, with nums starting [1,2]
Input: nums = [0,0,1,1,1,2,2,3,3,4]
Output: 5, with nums starting [0,1,2,3,4]

Constraints

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…