Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

Hash map:
On average Search and Delete are O( 1 + n/ # of bucket )
Because there might be more than one element have the same hash value.
And we have to do the search similar to the array inside that bucket.

Worse case for Search and Delete are O(n)
e.g. everything map to the same hash value.

Binary tree:
O(logn) "If balanced"
If the binary is not balanced, it can form a shape identical to array and take O(n)
To avoid that, some self-balancing algorithm is required.
Like RB-tree

- Chun-Fu Chao April 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Arrays:
Insert, delete and search are all O(n)

Hashmaps:
Insert and Delete O(1) whereas search is O(n)

Binary tree - all are O(lg n)

- datastructures April 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think Hashmaps has a delete operation worst case complexity of O(n) not O(1).

- sunny April 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

For Binary tree, delete and search not O(lg n) since it is not a BST and you have no hint to decide go to which branch

- yinwei318 April 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

For Binary tree, delete and search are not O(lg n) since it is not a BST and you have no hint to decide go to which branch

- yinwei318 April 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

"Indexing" an element in array is O(1)
And "indexing" an element in Linked List is O(n)
But indexing is not searching

- Chun-Fu Chao April 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

arrays should have O(1) time complexity. please correct if am wrong.
In linked list case it should be O(n)

- Anonymous April 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

^good soln .

- Anonymous April 22, 2012 | 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