Amazon Interview Question for Software Engineer / Developers


Country: -
Interview Type: In-Person




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

const int QUEUE_SIZE = 1000;
int push_ix = 0;
int pop_ix = 0;
int num_elements = 0;
int queue[QUEUE_SIZE];
void push_queue(int val) {
  if (num_elements == QUEUE_SIZE) return;
  queue[push_ix] = val;
  push_ix++;
  if (push_ix == QUEUE_SIZE) push_ix = 0;
  num_elements++;
}
int pop_queue() {
  if (num_elements == 0) return -1;
  int ret_val = queue[pop_ix];
  pop_ix++;
  if (pop_ix == QUEUE_SIZE) pop_ix = 0;
  num_elements--;
}

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

the problem with this approach is that whenever we pop the element the capacity of the queue keeps on decreasing since the tail index is always being increased.

- BJ October 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

do amazon really ask such questions?

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

I was asked this one, that's why I posted.

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

We can have two variable that will hold the index of location from where to pop and from where to push into the queue. We can simulate a cirular queue in this prob.

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

Its very easy question if its a simple Queue implementation. push() and pop() should be easily doable in O(1). It gets a little tricky when its random element deletion and not the first and last element.

In that case, you can swap the element to be deleted with the first or last element and do the appropriate push or pop operation on it.

- SN October 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

My question exactly. But if delete is not the same as pop, is it still a queue? Did the interviewer really insist on implementing a "traditional" queue?

- Chris October 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include<iostream>
#include<queue>
using namespace std;
template <class T>
void print(const queue<Y>&);
int main()
{queue<string>q; print(q);
q.push("jean"); print(q);
q.push("stefan"); print(q);
q.pop();
q.push("paul"); print(q);
q.push("jessica"); print(q);
q.push("david"); print(q);
q.pop();}
template <class T> void print(const queue<T>&q)
{queue<T>qq=q;
cout<<"size="<<qq.size();
if(qq.empty())cout<<";the queue is empty";
else{cout<<";front="<<qq.front()<<",back="<<qq.back()<<":("<<qq.front();
qq.pop();
while(!qq.empty())
{cout<<","<<qq.front();
qq.pop();}
cout<<").";}cout<<"\n";}

- sindhu October 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

LOL!

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

dude cut some slack..she obviously did not read the question properly happens sometimes

- Sirius April 27, 2014 | 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