Two Pointers pattern

Remove Duplicates from Sorted Array

Given a sorted integer array, remove the duplicates in place so each value appears once, keeping the relative order. Return k, the number of distinct values; the first k slots of the array must hold them. Watch it run step by step, then write your own pseudocode and get it checked by AI.

  • LeetCode 26
  • Easy
  • 2 approaches

Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.

Two PointersLeetCode 26

Easy

From the first idea to the best one

  1. 01 Brute force · second array O(n)O(n) space
  2. 02 Optimized · write index O(n)O(1) space
Each approach plays step by step, with its time and space.

What you will learn

  • How to read Remove Duplicates from Sorted Array and spot the two pointers pattern in it
  • Brute force · second array: O(n) time, O(n) space
  • Optimized · write index: O(n) time, O(1) space
  • The pseudocode for each approach, its line lit as the animation runs
  • Practice: write your own pseudocode and get it checked

More Two Pointers

See Remove Duplicates from Sorted Array run, step by step

Sign in and this page opens on the animation, with all 12 Two Pointers problems beside it.

DSA comes with the all labs plan and every ChaiCode batch.