Algorithms and Data Structures · Middle · Question 25 of 75

How do you find the middle of a linked list in one pass?

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.

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 25

Test yourself

Take the Algorithms and Data Structures · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz