Amazon Interview Question for Software Engineer / Developers






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

Usually in any "smart" implementation of dynamic array, it's size increases 2 times.

- gevorgk March 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

n he said if there are like millions of entries in an array, would you increase it to 2 million???

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

@gevorgk Could u explain a little more in detail pls

- Anonymous March 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The point of doubling in size is to reduce the amortized cost per operation to constant time. Any constant proportion will do, but common values are 2x or 3/2 times the current size (see the Wiki page for dynamic array).

For an array with millions of entries, I would say collect some statistics (of how fast and how often the array grows) and pick a constant proportion based on heuristics.

- chiz March 20, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

As Dynacmic array is required when we need to store more elements than the size of old array. hence it would be - Summ of : old array size + Extra Element count.

NewArrazySize = OldArray.Size() + ExtraElementCount();


PS: If we double the size of the arryay , memory will be wasted incase the extra elements are not equal to old array size.

Correct me if I am wrong.

Thanks
CG

- CG March 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

thats right.. thats why he was interested in knowing how much should you increase the size!

- kanurukh March 19, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@CG: Thats the whole point! In general we will not be knowing how many extra elements are there! If we were to know that in advance we will directly create an array of that size !!

- gaurav June 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

In case of c... answer would be to use realloc()
In case of java... use ArrayList<>

is that correct?

- andy March 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

well i think vector is dynamic array ...

- ridercoder November 01, 2010 | 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