Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

LinkedList is fast for insertion and deletion except random selection. In this scenario I think HashTable may be appropriate.

- RiponCoder February 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Linked list will insert in O(1) time but membership testing will be O(n) time. Hash table will be good for insert, delete, membership testing, but not random selection.
See below why storing the object in an ArrayList and the object's index into the array in a Hash table accomplishes all required functions in O(1) time.

- PSPete February 25, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Given object T which can return some unique key T.key(), maintain an Array<T> object and a HashMap<typeof(T.key())> Store the object in the array and the index of the array in the hash table at the location T.key() . This gives you random access (via array), insert, and deletion in constant O(1) time.

- PSPete February 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

An ideal solution would be to use HashTable + Doubly linked list.
In the hash table store value of element as key and its address as the hash value.(Just like LRU cache.)

The random selection part won't work in constant time though.

- aj February 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about a BST and a Hash map?

- Anonymous February 24, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More