Amazon Interview Question: Implement an algorithm to fin... | Glassdoor

Interview Question

Intern Software Development Engineer Interview

Implement an algorithm to find the 3rd to last element of a

  singly linked list of unknown size

Interview Answer

1 Answer


set two pointers at the head;
move the first one 3 steps first;
then move the two pointers at the same time, one step a time;
when the first pointer reach the tail, the second pointer get the result

helloslz on Dec 25, 2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.