08 / 16

How do you reverse a Linked List? (Iterative and Recursive)

Reversing a Linked List

javascript
  1. 1

    Iterative time complexity: O(n).

  2. 2

    Iterative auxiliary space: O(1).

  3. 3

    Recursive time complexity: O(n).

  4. 4

    Recursive auxiliary space: O(n) because of the call stack.

  5. 5

    The iterative solution is generally safer for very long lists because it avoids stack overflow.

Difficulty: 3/10

Follow-up Questions

  • How do you reverse a sublist between two positions?
  • How would you reverse a doubly linked list?