Amazon Interview Question for Software Engineer / Developers






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

use 2 stack...call in stack 1 and stack 2

insertion in queue is done by pushing on stack 1
extraction from queue in done by popping from stack 2

if stack 2 is empty then pop all from stack 1 and push to stack 2

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

Pop from stack 1 into stack 2 till pointer->next=null (i.e the last element to be popped from stack 1) this is the element to be deleted.
After that pop all the elements back from stack 2 to stack 1. This is in case there is another insertion before the next delete operation.

- Anonymous April 22, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Good Idea. But if you please publish complete code then that will help a lot.

- Shiva February 26, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Maybe this is just wishful thinking but is it possible to do this using just 1 stack ?

- abhimanipal April 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In the 2 Stack case . Time complexity of Queue.Get() will never be constant . Thats what idealy expected out of a queue's Get and Put operation . I hope that is not a requirement for the interviwer. Pls confirm.

- sucharit April 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use recursion to do it with one stack. The other is the implicit stack used is the call stack. If you use tail recursion you will not go out of memory (or stack overflow won't happen).

- logan August 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think I would say how by definition queue and stack are opposite (FIFO Vs LIFO). Can only make a queue out of stack by using some weird solution like 2 stack or recursion.

- Sandeep K April 28, 2013 | 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