Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: Phone Interview




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

Create an array of size 2n where is n is the size of object[]. If the size grows beyond, 2n/3 ( some threshold T), create a new array of size "3n" and copy the elements from overgrown array.
Add will to empty locations of the array while delete will be lazy delete. for each delete request, we should invalidate the data at that location and do not free up memory until there are enough cells that needs to be deleted.
Update should be trival in this case.

Disclaimer: Naive approach. Would love to see some awesome improved answers!

- AmzFAILFacebookFailMSFTFail January 05, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks for reply.

Can you provide the pseudo code for arraylist implementation ?

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

I think Lazy deletion should not happen in an array list. The expectation from array list is

Access = O(1)
Insertion/deletion = O(n)

When you delete an element, all the elements to the right have to be left shifted by 1 element . The reason is, again next access to the array list is O(1). If you flag the deleted elements this cannot meet that..

Also I think threshold should always be n (with capacity increment of kn where k is the number of times u exceed the size). However this is implementation dependent.

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

There is misunderstanding with operation delete(), because its prototype has not index variable, so if we can delete only from the end of an array we can use lazy deletion, else we should shift all elements placed next to the current.

- V.Krestyannikov January 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

If deletion happens at the end you are decrementing your length. So flagging is not neccessary.

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

100% ;)
I didn't say that we should use flagging.

- V.Krestyannikov January 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can review java.util.ArrayList or std::vector realization
@Carol Smith.
Your solution is very similar to standard, but usually size of an array will increase by two.

- V.Krestyannikov January 05, 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