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.

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

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

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

@gevorgk Could u explain a little more in detail pls

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

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.

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

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

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

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

@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 !!

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?

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

well i think vector is dynamic array ...

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.

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.