Enter your book access code

The curriculum, drills, tutor, and interviewer mode are for readers of Ace the Rust Interview. The code is printed in the Preface (Companion site access).

Don’t have the book yet? The landing page stays open — purchase unlocks this gym.

intermediate · order 72

Three-sum without aliasing traps

arr-three-sum-01Related book chapters: 15 (optional — this page is complete on its own)two-pointerarray

Slug: arr-three-sum-01 · Paired reading: Chapter 15

Prompt

fn three_sum(mut nums: Vec<i32>) -> Vec<[i32; 3]> — unique triplets that sum to zero, each triplet sorted, result sorted. Sort first; fix one index; two-pointer the rest. Dedup carefully.