Grokking Data Structures & Algorithms for Coding Interviews
0% completed
Solution: Reorder List
Problem Statement
Reorder a singly linked list so the nodes come in the order first, last, second, second to last, and so on, changing only the links. Return the head.
Examples
Example 1
- Input: head =
[1, 2, 3, 4] - Expected Output:
[1, 4, 2, 3]
Example 2
- Input: head =
[1, 2, 3, 4, 5] - Expected Output:
[1, 5, 2, 4, 3]
Example 3
- Input: head =
[1, 2] - Expected Output:
[1, 2]
What makes this hard
The required order needs the last node early, and a singly linked list gives you no way back
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%