Motorola Interview Question
Software Engineer / DevelopersAs I said, better solutions may exist.Heres another shot. Take two {tortoise and hare} pointers initialized to the start of the linked list. Then move hare 'm' elements ahead through sequential traversal.Now keep traversing the list advancing both pointers one node at time until hare reaches the end of the list.At this point the tortoise points to the 'm' the element from the last.The hare apparently wins this one :) As always, Please advise
Certainly we donot know the length of the linked list in advance.So possibly we could reverse the linked list & then traverse to the mth node. Other better solution(s) may exist. Please advise
- amit October 28, 2009