Skip to content
We areTOP 1%

Remove Duplicates from Sorted Array

EasyLeetCodeTwo Pointers
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

Keep a write index for the deduplicated prefix and a read index that scans the array; copy an element forward only when it differs from the last value written. O(n) time, O(1) space.

More in Two Pointers

Two Pointers questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Valid PalindromeLeetCodeEasy Solve Valid Palindrome on LeetCode (opens in a new tab)
2Remove Duplicates from Sorted ArrayLeetCodeEasy Solve Remove Duplicates from Sorted Array on LeetCode (opens in a new tab)
3Merge Sorted ArrayLeetCodeEasy Solve Merge Sorted Array on LeetCode (opens in a new tab)
4Sereja and DimaCodeforcesEasy 800Solve Sereja and Dima on Codeforces (opens in a new tab)
5Prepend and AppendCodeforcesEasy 800Solve Prepend and Append on Codeforces (opens in a new tab)
6Eating CandiesCodeforcesEasy 1100Solve Eating Candies on Codeforces (opens in a new tab)
7Kalindrome ArrayCodeforcesEasy 1100Solve Kalindrome Array on Codeforces (opens in a new tab)
8Alice, Bob and ChocolateCodeforcesEasy 1200Solve Alice, Bob and Chocolate on Codeforces (opens in a new tab)
9Two Sum II - Input Array Is SortedLeetCodeMedium Solve Two Sum II - Input Array Is Sorted on LeetCode (opens in a new tab)
10Sort ColorsLeetCodeMedium Solve Sort Colors on LeetCode (opens in a new tab)
11Container With Most WaterLeetCodeMedium Solve Container With Most Water on LeetCode (opens in a new tab)
123SumLeetCodeMedium Solve 3Sum on LeetCode (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account