Microsoft Interview Question

Find the n-th last element in a linked list.

Interview Answer

Anonymous

Dec 5, 2015

Have one pointer pointing the beginning of the list, and a second one pointing to the n-th element. Iterate through the list, updating both of the pointers, until the second one reaches the end of the list. Then return the first pointer.