Typorithm · easy

Reverse Linked List

reverse-linked-listlinked-listspointer-flipthree-pointersiterative
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Reverse Linked List

0%

Linked Lists

Walk the list flipping each next pointer backward, tracking prev, curr, and a saved next.

Reversing a list means making every node point to its predecessor instead of its successor.

You must save the next node before flipping, or the rest of the list is lost.

When curr reaches null, prev sits on the old tail — the new head.

01

Save next before flipping.

02

Flip curr.next to prev.

03

prev ends as the new head.

function reverseList(head) {
  let prev = null;
  let curr = head;

  while (curr !== null) {
    const next = curr.next;
    curr.next = prev;
    prev = curr;
    curr = next;
  }

  return prev;
}

Read the implementation

Connect each part of the code to the concept before you type.

1. New tail

prev starts null — it becomes the new list's end.

let prev = null

2. Save next

Store the next node before overwriting the pointer.

const next = curr.next

3. Flip the link

Point the current node backward to prev.

curr.next = prev

4. Advance prev

Move prev forward to the node just reversed.

prev = curr

5. New head

prev ends on the old tail, which is the new head.

return prev

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Reverse Linked List: Lesson & Practice · Typorithm | ApplyDjinn