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

Lesson 3.6 of 10 in this module Unrolled Pro

3Sum

Find every unique triple that sums to zero. From three nested loops with a set of results, to a hash set per anchor, to sorting, fixing one value and running two pointers in O(n²) with duplicates skipped in place. Then any target, the closest sum, counting triples under a budget, k-Sum, and why O(n²) is the practical floor.

about 10 min 4 Python examples 2 quick checks

Problem. Return all unique triples [a, b, c] from nums (three different positions) with a + b + c == 0. The answer must not contain the same triple twice.

text
[-1, 0, 1, 2, -1, -4]   →   [[-1, -1, 2], [-1, 0, 1]]
[0, 1, 1]               →   []
[0, 0, 0, 0]            →   [[0, 0, 0]]

ML context. "Pick three items whose costs hit a budget exactly, and list each combination once" is the same search: three model calls whose latencies sum to an SLO, three shards whose sizes fill a node. The two lessons that carry over are reduce k-Sum to (k − 1) loops plus two pointers, and de-duplicate by skipping equal neighbours in sorted data instead of hashing the results.


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 "3Sum"

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