ASAPUtils Logo ASAPUtils
Week 5

Reverse Linked List

Reverse Linked List explained through the processed-prefix invariant, safe prev-curr-next pointer order, C++ and JavaScript implementations, complexity, common pointer-loss bugs, and an interactive link trace.

The problem

Given the head of a singly linked list, reverse every next pointer and return the new head.

1 -> 2 -> 3 -> 4 -> 5 becomes 5 -> 4 -> 3 -> 2 -> 1

Related Problems