Pergunta de entrevista da empresa Google

Print mth to last elements of the linkedlist

Resposta da entrevista

Sigiloso

19 de ago. de 2012

Take two pointers that start from the head of the LinkedList. Start moving one of them one node a time. Start the second pointer after the first has reached to the mth element. Then move both the pointers one node at a time. When the first pointer reaches the end, the second pointer is at m nodes apart from the last which is what we needed. Now print all the elements from that node to the end.