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 69

Convert pointers to indices

list-index-01Related book chapters: 18, 21 (optional — this page is complete on its own)indices

Slug: list-index-01 · Paired reading: Chapters 18 and 21

Prompt

Given a singly linked list as Option<Box<Node>> with val / next, convert it into a flat arena: Vec<i32> values plus Vec<Option<usize>> next-links (same length). Return (values, nexts) with head at index 0 when non-empty. Empty input → two empty vecs.