PRACTICE · LINKED LISTS
Reverse Linked List
The challenge
Given the head of a singly linked list, reverse the list and return its new head.
Example
Input head = [1, 2, 3, 4, 5]
Output [5, 4, 3, 2, 1]
Every pointer now leads to the previous node.
Before you begin
- Read through the example and consider edge cases.
- Write down a simple solution before optimizing.
- Describe the time and space complexity of your approach.
A space to understand the problem. Use your favorite editor to write and run your solution.