Amazon.com

  www.amazon.com
Work in HR? Unlock Free Profile

Amazon.com Software Development Engineer I Interview Question

I interviewed in Seattle, WA and was asked:
"Remove the nth from last element in a singularly linked list in linear time."
Add Tags [?]
Answer

Part of a Software Development Engineer I Interview Review - one of 4,652 Amazon.com Interview Reviews

Answers & Comments

0
of 0
votes
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
0
of 0
votes
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
0
of 0
votes
That works too. The first way you only traverse once though.
- Jordan on Feb 20, 2012

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.