Interview Question
Share Lesson

Write a function `reverseLinkedList` that takes a head node of a singly linked list, reverses it in place, and returns the new head node.

You will be given the `head` as the input, and you should return the new head for the reverse linked list which is the current tail node. All the items should be in reverse order, starting with the tail (new head). The reverse should happen in place which means you should not create a new linked list.

`` ``

Breakdown

Share:

1. You only need to iterate through the list once which means it will be O(n) time.

2. You will need three pointers to store nodes and no additional data structures. This will be O(1) space.

3. The solution doesn't use a lot of code, but it does require writing the procedure carefully and in the correct order. Make sure you handle this and think through edge cases.

Share:

Write a function `reverseLinkedList` that takes a head node of a singly linked list, reverses it in place, and returns the new head node.
You will be given the `head` as the input, and you should return the new head for the reverse linked list which is the current tail node. All the items should be in reverse order, starting with the tail (new head). The reverse should happen in place which means you should not create a new linked list.
`` ``