Amazon Interview Question for Software Engineer Interns


Country: United States
Interview Type: Phone Interview




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

[ Avg / Worst Case ]
                                     Insert                 Search
HMap                            1/n                        1/n   
UnorderedArray            1/1                        n/n    
UnordLinkedList            1/1                        n/n
Queue  <Queue does not denote a DS implementation, it is an ADT.
               Refer to possible implementation types, like two items listed above>

- Le Snob. March 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

HashMap Search - O(1) uses non-duplicate keys, map.get(key),
Insert O(1) map.put(key,value)

Array- Insert (at the end) O(1), Insert in the middle O(n), Search O(n)

LinkedList- Insert O(1), Search O(n)
Queue: same as LinkedList

- Trier March 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

HashMap : Insert - O(1), search (by key) O(1)
Array : Insert - O(1), search O(n)
Linked List : Insert - O(n), search O(n)
Queue : Insert (by front pointer) - O(1), search O(n)

- arsragavan March 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Search by index in Array? That would make it a hashMap (with possibility the trivial hash h(i) = i).

- S O U N D W A V E March 17, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

ya sorry.. I will edit it

- arsragavan March 17, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Linked list insert is O(1)

- Radzell March 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

^ yeah, the actual insertion procedure if O(1) (just reroute some pointers).

However, if you want to insert a node into the middle of a linked list, you really got to start from the beginning traverse to the position where you want to insert the node and then do the actual insertion procedure. The traversing would then take O(n).

Insertion at the beginning is O(1) (no traversing necessary).
And, inserting at the end could take O(1) if you kept a reference to the tail of the list.

- Jonathan March 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Jonathan,
Why would you want to insert in the middle of a plain linked list?

- LookSkywalker March 19, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think we should consider sorted and unsorted situations for array, linked-list.

- Anonymous March 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if the queue uses array internally
Insert - O(1), search O(n), dequeueO(1)
If the queue uses hash map internally
Insert - O(1), search O(1), dequeueO(n)

- Satish Kumar March 19, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

------------------ |Insert* | Search
-------------------|-----------------------------------------------------------
HashMap | O(1) | O(1)
--------------------------------------------------------------------------------

Array | O(1) | O(n)
--------------------------------------------------------------------------------

LinkedList | O(1) | O(n)
--------------------------------------------------------------------------------

Queue | O(1) | O(n)
--------------------------------------------------------------------------------

*Assuming insertion at the end

- praveenkcs28 March 21, 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