Easy · Linked Lists

Reverse linked list (Linked lists)

Given the head of a singly linked list, reverse the list in place and return its new head (the old tail).

Examples

Example 1

{
  "values": [1, 2, 3, 4, 5]
}

Output: 5 → 4 → 3 → 2 → 1

Example 2

{
  "values": [7, 8, 9]
}

Output: 9 → 8 → 7

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Linked Lists problems