Interview's MateDSA Visualizer
Interview's Mate

DSA Visualizer

Learn by watching algorithms run

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
All topics
DATA STRUCTURES

Linked Lists

Nodes joined by next pointers - cheap to relink, slow to index.

Beginner9 problems3 interactive subtopicsO(n) time · O(1) space
Practice in AI DSA
WalkthroughOverviewRecognize itMistakes & edge casesKnowledge check (3)Practice
Algorithms & custom examples (3)Open in full playground →
STEP 1/5Start
prev = None, curr = 1
None
1
2
3
None
prev
curr
  • visited / done
  • result
Space Play←→ StepR Replay
1 / 5
PYTHONhead = 1 -> 2 -> 3 -> None
1def reverse_list(head):
▶2 prev, curr = None, head
3 while curr:
4 nxt = curr.next
5 curr.next = prev
6 prev = curr
7 curr = nxt
8 return prev
STEP 1 OF 5Setup

Start

prev is None and curr is node 1. Nothing is reversed yet.

VARIABLES

prev
None
curr
1
reversed part
-
02

Intuition & complexity

The core mental model, trade-offs, and Big-O cost.

What it is

Each node holds a value and a reference to the next node. Reaching position i means walking i steps from the head.

Why it matters

Inserting or removing next to a node you already hold is O(1) - nothing has to shift.

Think of it like this

A treasure hunt: each clue tells you where the next one is hidden.

Use it when

  • Frequent inserts or deletes once you hold the node
  • Building queues, LRU caches or adjacency lists
  • Problems that hand you a ListNode

Avoid it when

  • You need random access by index
  • Memory is tight - every node carries pointer overhead

Complexity cheatsheet

OperationTimeSpace
Access node iO(n)O(1)
Insert or delete after a known nodeO(1)O(1)
Reverse in placeO(n)O(1)

Often confused with: arrays - O(1) indexing, but O(n) inserts in the middle.

03

How to recognize it

Clues in interview prompts that point straight to this pattern.

ListNodeheadreversemerge two listskth from the end
  • O(1) extra space on a list means re-pointing nodes, not copying values
  • A dummy head node removes special cases at the front
04

Mistakes & edge cases

Catch common off-by-one bugs and corner cases before submitting.

Common mistakes

  • Overwriting curr.next before saving it - the rest of the list is lost
  • Forgetting to return the new head
  • Not handling an empty list

Edge cases to test

  • Empty list (head is None)
  • A single node
  • A list with a cycle - reversal never ends
Interview tip: Draw three boxes and their arrows on the whiteboard before writing pointer code.
05

Knowledge check

Quick check to lock in the intuition.

Question 1 of 3

During reversal, why save nxt = curr.next before anything else?

06

Practice

Apply what you just watched on real interview problems.

Generate Linked List problem in AI DSA Practice →
  • BeginnerReverse Linked ListLeetCode 206 ↗ (opens in a new tab)
  • IntermediateRemove Nth Node From End of ListLeetCode 19 ↗ (opens in a new tab)
  • AdvancedReverse Nodes in k-GroupLeetCode 25 ↗ (opens in a new tab)
SearchingStacks