PubMatic Interview Question

How would you find middle element of link list.

Interview Answer

Anonymous

Aug 15, 2017

Solution : Take two pointers. Set both pointers to first node. Increment first pointer with two nodes and second pointer with one, at a time. Loop until the 1st pointer reaches the end. At this point, the 2nd will be at the middle.