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

Lesson 7.6 of 8 in this module Unrolled Pro

Remove Nth Node From End of List

Delete the n-th node from the end of a singly linked list in one pass. From copying node references into an array (O(L) space), to counting the length and walking to the predecessor (two passes), to two pointers with a fixed gap of n starting at a dummy node (one pass, O(1) space). Then invalid n, rotating a list by k, keeping only the last k nodes, and the streaming version: the checkpoint from n saves ago with a ring buffer of n.

about 10 min 5 Python examples 2 quick checks

Problem. Given the head of a singly linked list and an integer n, remove the n-th node from the end and return the head. n is between 1 and the length.

text
1 → 2 → 3 → 4 → 5,  n = 2     →   1 → 2 → 3 → 5
1,                  n = 1     →   None
1 → 2,              n = 2     →   2          (the head itself is removed)

Two difficulties: you don't know the length, and to delete a node you need its predecessor. Which could be "the node before the head", hence the dummy node from lesson 7.1.

ML context. "The n-th from the end" is a recency question: the checkpoint from three saves ago, the batch five steps back when the loss spiked, the last k log lines before a crash. In a stream you can't go back, so you keep exactly n items in a ring buffer (Change D), the same fixed-gap idea in another form.


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 Nth Node From End of 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