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

How trie?

- dev September 30, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

but if the number is say 9999 u will have to use dat much space..isnt it?

- Anonymous October 01, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Use a set.

- bouncmpe October 01, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Just curious, what does it mean by O(1)
O(1) for worst case? or average case?

- Vincent October 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

O(1) means constant time

- yduck October 04, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can use dynamic hashing:
hash table will be of size 10 here... that is, the index of the array will be from 0 to 9 .. and the remaining is same as trie...

- padmaja October 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use hashtable implementation with Seperate Chaining !! If the Hash Function is gud(perfect Hashing :P) one can do all these operations in O(1) time ...Otherwise Worst case time will be O(n) but expected time is O(1)...Using tries Expected time will also be O(n) So wont do here

- Anonymous October 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Question must be refined , its not for searching it is get any active element . The answer to this question is combination of Hashing and double linked list approach . after Much discussion i came to this answer , he accepted the answer

- Anonymous October 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

can u throw more light on ur hashing + doubly linked list approach

- Anonymous October 06, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

what happens when many numbers map to the same hash key? Worst case for hash+linked list is O(N) right?

- dee October 10, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int MaximumContigiousSumInACircle(int *A, int *n)
{
int MaxSumInRegularArray = MaximumContigiousSum(A,n);
int MaxContigiousSumFromZeroInARun = A[0], MaxContigiousSumFromZero = 0, FirstIndex = 0;
for(int i = 1; i < n; i++)
{
if(MaxContigiousSumFromZeroInARun + A[i] > A[i])
{
MaxContigiousSumFromZeroInARun += A[i];
if(MaxContigiousSumFromZero < MaxContigiousSumFromZeroInARun)
{
MaxContigiousSumFromZero = MaxContigiousSumFromZeroInARun;
FirstIndex = i;
}
}
else
break;
}
int MaxContigiousSumFromLast = 0, MaxContigiousSumFromLastInARun = A[n - 1];
for(int i = n - 2; i >= 0 && i > FirstIndex; i--)
{
if(MaxContigiousSumFromLastInARun + A[i] > A[i])
{
MaxContigiousSumFromLastInARun += A[i];
if(MaxContigiousSumFromLastInARun > MaxContigiousSumFromLast)
MaxContigiousSumFromLast = MaxContigiousSumFromLastInARun;
}
else
break;
}
if(MaxContigiousSumFromLast + MaxContigiousSumFromZero > MaxSumInRegularArray)
return MaxContigiousSumFromLast + MaxContigiousSumFromZero;
else
return MaxSumInRegularArray;

}

int MaximumContigiousSum(int *A, int n)
{
int MaxSumInARun = A[0], MaxSum = 0;
for(int i = 1; i < n; i++)
{
if(MaxSumInARun + A[i] > A[i])
MaxSumInARun += A[i];
else
MaxSumInARun = A[i];
if(MaxSum < MaxSumInARun)
MaxSum = MaxSumInARun;
}

return MaxSum;
}

- Winston Wolfe October 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Key: Hash code of data
Value: Memory address of this data

If data isn't stored in a single memory cell, then value must has all memory cell addresses which data stored in.

- shiva123 October 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

LinkedHashMap

- adidacodes March 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Obviously hashing can solve this issue without any doubt but I would have to answer it to be a Trie..

- Anonymous September 30, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You can use an hashtable with key as the number itself and value the number of time it occurs. So if you want to delete a duplicate number, you can reduce the count by 1

- Anonymous October 01, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Anonymous
ur sol is gud...but d problem with dat approach is that it limits d range of numbers

- guneesh October 01, 2011 | Flag


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