VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 07: Linked lists and caches

Lesson 7.3 of 8 in this module Unrolled Pro

Middle of the Linked List

Find the middle node of a singly linked list. From copying the nodes into an array (O(n) space), to counting the length and walking halfway (two passes, O(1) space), to slow and fast pointers that finish in one pass because one moves twice as fast. Then the first middle instead of the second, the k-th node from the end with a fixed gap, splitting a list in half for merge sort, and the streaming twin: sampling uniformly from a stream of unknown length with reservoir sampling.

about 10 min 5 Python examples 2 quick checks

Problem. Given the head of a singly linked list, return the middle node. With an even number of nodes, return the second of the two middle nodes.

text
1 → 2 → 3 → 4 → 5          →   node 3
1 → 2 → 3 → 4 → 5 → 6      →   node 4      (the second middle)

The difficulty: a linked list doesn't know its length, and you can't jump to position n/2. The technique you learn here, two pointers moving at different speeds, solves a whole family of problems (lessons 7.4 and 7.6).

ML context. "Find the middle without knowing the length" is the linked-list version of a streaming question: data arrives once, you don't know how much there is, and you can't store it all. The streaming twin, picking a uniformly random item from a stream of unknown length, is reservoir sampling, used to sample training examples or log lines from a stream in one pass (Change D).


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 "Middle of the Linked List"

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