Amazon Interview Question: Remove the nth from last elem... | Glassdoor

Interview Question

Software Development Engineer I Interview Seattle, WA

Remove the nth from last element in a singularly linked

  list in linear time.

Interview Answer

3 Answers


The general idea is to keep a pointer n elements back from the current element as you're traversing the linked list looking for the last node. There are some edge cases when coding it. O(n) time, O(1) space.

Interview Candidate on Jan 13, 2012

How about? Traverse once find length. Then find n-kth element. Still linear complexity in time and 0 addl space

kvr on Feb 20, 2012

That works too. The first way you only traverse once though.

Jordan on Feb 20, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.