VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 03: Two pointers

Lesson 3.3 of 10 in this module Unrolled Pro

Remove Duplicates from Sorted Array

Keep one copy of each value in a sorted array, in place, and return how many are left. From shifting elements left (O(n²)) and building a new list (O(n) memory), to a read pointer and a write pointer in one pass. Then at most k copies, unsorted input, and de-duplicating sorted ids in a data pipeline.

about 10 min 3 Python examples 2 quick checks

Problem. nums is sorted in non-decreasing order. Remove duplicates in place so each value appears once, keeping the order, and return k, the number of unique values. The first k slots must hold them; what's after doesn't matter.

text
[1, 1, 2]                       →   k = 2,  nums[:2] = [1, 2]
[0, 0, 1, 1, 1, 2, 2, 3, 3, 4]  →   k = 5,  nums[:5] = [0, 1, 2, 3, 4]

ML context. Sorted id lists are everywhere: user ids before a join, document ids from a retrieval shard, sorted event keys in a log. De-duplicating them in place, in one pass and without a hash set, is how you keep a join from double-counting rows, and it's exactly what a "unique" step does on sorted data.


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Remove Duplicates from Sorted Array"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee