Algorithms and Data Structures · Middle · Question 25 of 75
How do you find the middle of a linked list in one pass?
- ✓Correct answer: Slow and fast pointers: when fast ends, slow is in the middle
- 2Read the list's length property and jump to
length / 2 - 3Reverse the list, then walk from both ends until they meet
Explanation
A singly linked list doesn't know its length, so you'd need two passes otherwise. The slow/fast pointer trick finds the middle in one pass with O(1) memory.