Vismo · Create · Library · Topics · Guides · Pricing

Two Pointers Removing Sorted Duplicates

An array walkthrough showing a slow pointer i and fast pointer j scanning a sorted list to remove duplicates in place. The animation highlights how j compares neighboring values while i marks where the next valid element should be written, illustrating the core two-pointer compaction pattern used in array deduplication problems. Useful for students studying in-place array algorithms and common coding-interview techniques like the 'remove duplicates' family of problems.

16:9 · every frame verified for overlaps, spacing and edges before rendering

The prompt that made it

class Solution { public int removeDuplicates(int[] nums) { int i=0; for(int j=0;j<nums.length;j++){ if(nums[j] == nums[i] && nums[j]==nums[j+1]){ continue; }else{ nums[i]=nums[j-1]; i++; }if(j==nums.length-1){ nums[i]=nums[j]; } } return i; } }

Make your own version

Make the next one in this series

Related animations

Minimum spanning tree with Kruskal's algorithm
Minimum spanning tree with Kruskal's algorithm

A weighted graph is processed by sorting all edges from cheapest to most expensive, adding each one only if it…

Binary search tree: smaller left, larger right
Binary search tree: smaller left, larger right

Values 50, 30, 70, 20, 40, 60, 80, and 35 are inserted one at a time into a binary search tree, with each comp…

Hash tables: a formula decides where each key lives
Hash tables: a formula decides where each key lives

Seven buckets receive keys according to key mod 7, with collisions stacked as chains beneath each bucket. A lo…

Big-O: how running time grows with the input
Big-O: how running time grows with the input

This animation plots O(1), O(log n), O(n), O(n log n), O(n^2), and O(2^n) on shared axes, showing how each cur…

Linear search vs binary search: count the comparisons
Linear search vs binary search: count the comparisons

This animation compares two ways to find the value 51 in a sorted list of 16 numbers. Linear search checks eac…

Quicksort: pick a pivot, partition, recurse
Quicksort: pick a pivot, partition, recurse

This animation walks through the Lomuto partition method used in quicksort, choosing the last element as pivot…