Reverse Linked List — Linked List
Flip a chain of linked items so the order runs backwards, then return the new first item; the chain may be empty.
Linked List · Easy
The problem
A music player stores its queue as a chain of songs, and you want to play it backwards. Given the head of a singly linked list, turn the list around so the last node comes first, and return the head of the turned-around list.
The story
Your road-trip playlist is stored as a chain: each song knows only which song comes after it. Halfway through the drive, everyone agrees the last song should play first. Rewire the chain so it runs backwards, and hand back the new first song. The playlist holds at most 12 songs, and it might be empty.
What to return
- Return the head of the reversed list (None / null if the list is empty).
- The result is read back from the head, so the order of values must be exactly reversed.
Constraints
- 0 <= length of head <= 12
- -50 <= node value <= 50
Example
- Input
head = 4→8→15→16→23- Output
23→16→15→8→4