DSA Factory
All free lessons
Level 2 · Core

Free Linked lists lessons

12 lessons, about 150 minutes in all. Each teaches one idea with a visual, then gives you one problem built for it. Read the lessons here, then create a free account to solve the problems and keep your progress.

Stage 0Walking nodes

  1. Count the nodesWalk from head to tail, counting each node until next is null.8 min
  2. Find first occurrenceWalk with an index counter and return the position of the first matching value.8 min
  3. Value at indexCount hops from the head to reach the target position, guarding against short lists.8 min
  4. Check if sortedLook ahead to curr.next to compare adjacent nodes without running off the end.9 min

Stage 1Changing links

  1. Turn the chain aroundReverse a linked list in place by flipping each link to point at the node before it.15 min
  2. Cut a value out of the chainRemove every node holding a given value by making the node before it skip over, with a dummy node at the front so the head is not special.14 min
  3. Slot a new node into placeInsert a value into a sorted list by walking to the node before its place and linking the new node in.13 min
  4. Swap the neighboursSwap every two neighbouring nodes by rewiring three links per pair, not by swapping the values.15 min

Stage 2Fast and slow pointers

  1. Find the middle without countingFind the middle of a chain in one walk by sending a fast pointer two steps at a time beside a slow pointer that goes one.12 min
  2. Does the chain loop backDetect a loop by letting a fast runner chase a slow one: if there is a loop, the fast one eventually laps and catches the slow one.16 min
  3. Count from the backRemove the n-th node from the end in one walk by keeping two pointers a fixed distance apart.14 min
  4. Does the list read the same backwardsCheck whether a list is a palindrome in one pass and with no extra memory, by reversing its second half.18 min

There’s more after this

These are the opening stages of Linked lists. The full path climbs on to harder problems and a mastery test. Create a free account and we’ll keep your place.

Start the full path free