In a singly linked list, how would you implement the two-pointer technique to find the middle element of the list?
Move both pointers at the same pace, and the second pointer will always be ahead of the first pointer. When the second pointer reaches the end, the first pointer will be at the middle.
Start both pointers at the head, and move the first pointer to the right and the second pointer to the left. The middle will be the average of the two pointers.
Start both pointers at the tail of the linked list, and move both pointers toward the head at the same pace.
Start both pointers at the head, and move the second pointer twice as fast as the first pointer. When the second pointer reaches the end, the first pointer will be at the middle.
This question is part of this quiz :
Quiz on Two Pointer Technique for DSA