Linked List Exercises: Practice Problems (with Solutions)
Time to practice. Solve each problem yourself first — sketch the nodes on paper, trace your pointer moves on a tiny example, and reason about time and space before you write a line. Only then open the answer sheet. Every View answer link jumps to a full, multi-language solution on the linked list solutions page.
How to practice: Drawing the boxes-and-arrows by hand is not optional for linked lists — it is how you avoid losing the tail. If you’re stuck, re-read the operations and fast & slow pointers pages before peeking.
Warm-ups
Q1. Reverse a singly linked list. Given the head of a list, reverse it and return the new head. Target O(n) time and O(1) space.
Q2. Find the middle node. Return the middle node of a singly linked list in a single pass. For an even-length list, return the second of the two middle nodes.
Core problems
Q3. Detect a cycle. Determine whether a linked list contains a cycle. Use O(1) extra space.
Q4. Merge two sorted lists. Given the heads of two sorted linked lists, splice them into one sorted list and return its head. Reuse the existing nodes (no new allocation for values).
Q5. Remove the Nth node from the end. Given the head and an integer n, delete the nth node counting from the end and return the head. Do it in one pass.
Challenge
Q6. Palindrome linked list. Return whether the list reads the same forward and backward. Aim for O(n) time and O(1) extra space.
Q7. Detect the cycle’s start node. If the list has a cycle, return the node where it begins; otherwise return null. Use O(1) extra space.
Done? Review every solution on the linked list answer sheet — even the ones you solved, since there’s often a cleaner approach. Then continue to stacks.