easyLinked ListAmazonGoogleMicrosoft
Reverse Chain
A singly linked chain of beads. Rebuild it so the last bead becomes the first and all arrows face backward.
Given the head of a singly linked list, reverse it and return the new head.
Choose approach
1
curr
2
3
4
5
nil
prev
1/12
Narrationstep 1 of 12
prev = null, curr = head. Walk the list; at each node flip its arrow backward.
Variables
prev=null
curr=1
How to think about it
- Three pointers suffice; no auxiliary list.
- Save next first — otherwise the forward link is lost after the flip.
- Walk ends when curr is null; prev holds the new head.
Edge cases to catch in interview
- Empty list → null.
- Single node → unchanged.
- Two nodes → swap neighbours.
Examples
Example 1
[5,4,3,2,1]{"values":[1,2,3,4,5]}
Example 2
[]{"values":[]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed