roadmap/Linked List

Topic 6 / 16

Linked List

MediumLinear~4 days
Moderate
progress0 / 15 solved

Pointer manipulation, slow/fast runners, and reversal patterns.

Linked lists are chains of nodes connected by pointers. Unlike arrays, there's no random access โ€” traversal is always O(n). Most problems are solved with pointer manipulation: the slow/fast runner technique, reversal in-place, and maintaining extra pointers to keep track of prev/next.

  • โ—†Detect a cycle in a linked list
  • โ—†Find the middle node
  • โ—†Reverse a list or sublist
  • โ—†Merge two sorted lists
  • โ—†Remove nth node from end
Slow / fast pointers
Detect cycles, find midpoints. Fast moves 2x speed of slow.
In-place reversal
Swap next pointers iteratively with prev, curr, next variables.
Dummy head
Add a sentinel node before head to simplify edge cases (empty list, removing head).
Merge
Compare heads of two lists, advance the smaller one.
Linked List
Reverse a Linked List
linked list
1
curr
โ†’
2
โ†’
3
โ†’
4
โ†’
5
โ†’ null
curr
prev
next
reversed
Initialize: prev=null, curr=head
We'll reverse by redirecting each node's next pointer to its predecessor.
step 1/16
Brute force
Store all nodes in an array; process from there โ†’ O(n) space.
Observation
Most operations only need O(1) extra space if we adjust pointers in place.
Optimization
Use 2-3 pointers (prev, curr, next) and update links in a single pass.
Final complexity
O(n) time, O(1) space for most in-place operations.

Why is a dummy head node useful in linked list problems?

In Floyd's cycle detection, what does it mean when slow and fast pointers meet?

To remove the nth node from the end in one pass, what gap do you maintain between two pointers?

Check each question you can answer confidently before moving to the next topic.

Progress is saved on this device