All puzzles › Linked Lists

Linked Lists Practice Problems

26 puzzles (9 easy, 13 medium, 4 hard), 1 free, in Python, JavaScript and C++.

A linked list is a chain of nodes where each one only knows the next. You cannot jump to the middle, so every problem is about careful pointer handling: keeping hold of the node you are about to lose, rewiring in the right order, and not walking off the end. Interviewers like them because there is nowhere to hide sloppy thinking.

How to spot a linked lists problem

The problem will hand you a head node. Two tools cover most of them. A dummy node in front of the head removes the special case for an empty or one-node list. A fast pointer that moves two steps for every one the slow pointer takes finds the middle, and finds a loop if there is one.

New to it? Read the lesson first: Linked Lists.

The puzzles, easiest first

  1. Reverse Linked List (Easy, free): Given a linked list, passed in as its values from front to back, return its values in reverse order.
  2. Biggest in the Chain (Easy): Given a linked list, passed in as its values, return the biggest value, or null if it's empty.
  3. Count a Value (Easy): Given a linked list, passed in as its values, and a target, return how many nodes hold the target.
  4. Is the Chain Sorted? (Easy): Given a linked list, passed in as its values, return true if it's sorted from smallest to largest.
  5. Length of the Chain (Easy): Given a linked list, passed in as its values, return how many nodes it has.
  6. Middle of the Linked List (Easy): Given a linked list, passed in as its values, return the middle value.
  7. Remove Duplicates from Sorted List (Easy): Given a sorted linked list, passed in as its values, remove the duplicates so each value appears once.
  8. Remove Every Match (Easy): Given a linked list, passed in as its values, and a target, remove every node holding the target and return what's left, in order.
  9. Splice a Node In (Easy): Given a linked list, passed in as its values, a position n, and a value, insert the value right after position n and return the new list.
  10. Drop the Nth Node (Medium): Given a linked list, passed in as its values, and a position n (starting from 0), remove the node at n and return the values left.
  11. Last One Standing (Medium): n players numbered 0 to n - 1 sit in a circle.
  12. Merge Two Sorted Lists (Medium): Given two sorted lists, merge them into one sorted list.
  13. Nth From the End (Medium): Given a linked list, passed in as its values, and n, return the value n places from the end, or null if the list is shorter than n.
  14. Odd and Even Positions (Medium): Given a linked list, passed in as its values, return the nodes at odd positions first (1st, 3rd, 5th), followed by the ones at even positions (2nd, 4th), each group keeping its order.
  15. Palindrome Chain (Medium): Given a linked list, passed in as its values, return true if it reads the same forwards and backwards.
  16. Partition Around a Value (Medium): Given a linked list, passed in as its values, and a pivot, move every value below the pivot ahead of every value at or above it.
  17. Recycle the Bullets (Medium): Creating a fresh bullet every shot would make the garbage collector stutter, so games keep an object pool of reusable slots.
  18. Rotate the Chain (Medium): Given a linked list, passed in as its values, and k, rotate it right so the last k nodes move to the front.
  19. Swap Every Pair (Medium): Given a linked list, passed in as its values, swap every pair of neighbors and return the result.
  20. The Middle Node (Medium): Given a linked list, passed in as its values, return the middle value.
  21. Weave Two Chains (Medium): Given two linked lists, passed in as their values, weave them together one node at a time, starting with the first list.
  22. Where They Join (Medium): Given two linked lists that join and share the same tail, passed in as their values, return the first value of that shared tail, or null if they don't share one.
  23. Add Two Chains (Hard): Given two numbers stored as linked lists, one digit per node with the ones digit first, return their sum in the same format.
  24. Does It Loop? (Hard): Given a list where next[i] is the index node i points to, and -1 means the end, return true if following the links from node 0 loops forever.
  25. Drop Every Duplicate (Hard): Given a sorted linked list, passed in as its values, remove EVERY value that appears more than once, keeping only the values that showed up exactly once.
  26. Reverse a Section (Hard): Given a linked list, passed in as its values, and two positions left and right (starting from 0), reverse just the part from left to right and leave the rest alone.

Practice another pattern

Or browse by subject

Browse all 676 puzzles