Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: Phone Interview




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

Hashmaps are better for average case search, generally O(c), where c is the number of elements in the longest linked list associated with an entry in a hashmap. (This is when we are making use of Chaining to avoid hash collision) We make sure that this happens with the help of load factor.

In the worst case scenario, c = n, i.e. there is only one chain and array and hashmap are practically equivalent.

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

If index is in the form of string then hashmap is better than array . hashmap perform very fast for large number , if it is small array and hashmap are same ... the time to calculate hash function has to be consider ..

- Rambabu Yerajana April 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

worst case searching for Hash map is O(logn) because their internal implementation uses the B+/AVL Trees( It depends on compiler ). Other hand of arrays takes O(n)

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

I think you are wrong over here, hashmap's worst case search time is O(n).
Reference from Wikipedia and other places.

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

They are implemented internally as RB trees. So the ammortized cost is small. O(1) , but the worst case can be O(nlogn ) . assuming Lg n for rotations and doing this for n elements.

- scofield April 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its all about the expected(realistic) performance. Same theory applied to bubble sort and qsort, both sorting are O(n^2) running time, but qsort is used everywhere since it's expected running time is o(N*lgN) unless the input data is sorted or almost sorted.

- chlam98 July 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Array is a hashmap with 1-1 mapping, to save space we use hashmap
so if the data is limited and space is not a constrant then Array is better else
Hash map is the choice

- naive April 03, 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