Easy · Arrays

Remove Duplicates in Place

Given an integer array nums sorted in non-decreasing order, remove the duplicates in place so the first k slots hold each distinct value exactly once, in their original order, and return k (whatever is left after slot k does not matter).

Examples

Example 1

[1,1,2,2,3]

Output: length 3

Example 2

[0,0,1,1,1,2,3]

Output: length 4

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Arrays problems