54 / 75
E

Reverse Linked List

#54
linked-listrecursion

Iteratively reverse pointers: track prev, current, and next nodes.

Example:

Input:head=[1,2,3,4,5]
Output:[5,4,3,2,1]

Common Mistakes:

  • Losing reference to next node before reversing pointer
  • Not returning prev at the end (returning curr which is null)
  • Trying to reverse without tracking 3 pointers
  • Overcomplicating with recursion when iterative is simpler

Notes:

Fundamental linked list operation. Time O(n), Space O(1) iterative. Can also solve recursively with O(n) space.

54/75
Reverse Linked List