What is the time complexity of finding the middle of a linked list?
What is the time complexity of finding the middle of a linked list?
Approach: Analyze the slow and fast pointer approach.
O(n). By using two pointers where one moves twice as fast as the other, the middle can be found in one pass.
Follow-up: Why is this better than counting elements first?
Key concepts: pointers, linear time.