Turn a linked list around
Reported in interviews at (where)
Reverse the singly linked list that starts at head, so that its last node comes first and every next pointer points the other way. Return the new head.
An empty list stays empty. Try it in one pass with O(1) extra memory.
- Input
head = [4,8,15]- Output
[15,8,4]
The node holding 4 ends up last, pointing to nothing.
- Input
head = [7]- Output
[7]
One node is its own reverse.
- Input
head = []- Output
[]
An empty list has nothing to turn around.
Limits
0 <= number of nodes <= 100000-100000 <= Node.val <= 100000
Hints
Hint 1
Walk the list keeping three pointers: the node before, the current node and the one after it.
Hint 2
Point the current node back at the one before, then step all three forward. The last node you reach is the new head.
Where this was reported
- GlobalLogic, Technical interview, 2026 (GeeksforGeeks)
Our own problem on the task these candidates describe; the wording, examples and tests are InternDoor’s.
Run your code to check it on the examples. Submit runs every hidden test.
