Data Structures19 sections · 729 units
Open in Course

Reverse Linked List Solution

Implement your solution

You now understand both approaches. The iterative three-pointer technique is more space-efficient. The recursive approach is cleaner to write but uses O(n)O(n) stack space.

For interviews, know both. Start with iterative unless the problem particularly asks for recursion.

Common bugs:

  • Forgetting to save next before overwriting current.next
  • Returning current instead of prev (current is null at the end)
  • Not handling empty list or single-node list

Test your solution on: empty list, single node, two nodes, longer lists. Time: O(n)O(n). Space: O(1)O(1).