Amazon Interview Question for Software Engineers


Team: Seattle
Country: United States
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
0
of 2 vote

O(1) for inserting a node in a linked list. Just take a pointer to the beginning of the list, then prepend it. For appending, you'd need to keep a pointer to the end of the list in order to achieve O(1), otherwise you have to pay an O(n) search cost for the end of the list which you get by traversing the list 1 by 1.

~O(1) time complexity for the hash map. You pay the time for the hash (which, if designed correctly, is O(1) and then you append to the bucket in the hash map (technically O(k) where k is the expected number of elements in the bucket, but if you choose the right hash where there are no collisions this becomes O(1)).

- JC315 September 02, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The answers varies on conditions,

Insert in a sorted LinkedList is O(n).
Insert in a unsorted LinkedList is O(1).

HashMap is a bit more complex, usually O(1) but worst case O(n).
This is depending on your hash function and collisions etc.

- Marcus.Danielsson.86 September 02, 2016 | 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