Hardware interview practice
Reverse a singly linked list
Reverse a singly linked list in place and return its new head.
Reviewed example
Work through one case
Input
head = 1 -> 2 -> 3 -> nullExpected output
3 -> 2 -> 1 -> nullEach next pointer is reversed once, and the original tail becomes the new head.
What to cover
Requirements
- Do not allocate replacement nodes.
- Preserve the next node before changing the current link.
- Return null for an empty input list.
