Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Remove Duplicates from Sorted Array

Easy
two-pointersarray

Given a sorted integer array nums, remove the duplicates in place so that each unique element appears only once, keeping the relative order. Return the resulting deduplicated array.

Input: one line of space-separated integers (sorted). Output: the deduplicated array, space-separated.

Example 1
Input:
1 1 2
Output:
1 2
Example 2
Input:
0 0 1 1 1 2 2 3 3 4
Output:
0 1 2 3 4

Constraints

  • 1 ≤ nums.length ≤ 3·10^4
  • nums is sorted in non-decreasing order.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.