Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

We could use an allocator which allocates chunks of size x as required and maintain linked lists. Array lists would waste a lot of space since they allocate more than absolute required space.

- Noobie September 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

since u said number of queues are not fixed you can take a linked list where each node will contain address to a queue so whenever u need a new queue you just create a new node ..
Pros ..
1) Flexibility of size
2) Max. space utilization

Cons ..
1) no random access
2) overhead of pointer

definition of node of linked list will depend on how queue is implemented ..
1) if size of queue is constant use array .. then node is defined as follows :
struct node
{
int * queue; // queue is name of pointer pointing to base address of queue
struct node * link // link to next node
};

2) if variable size of queue is required and u don't mind the pointer overhead you can use linked list ... then definition of node will be ..

struct Qnode // node of queue using linked list
{
int data; // store data at node
struct Qnode * next; // pointer to next node
};
struct node // node containing start address of queues
{
struct Qnode * queue; // stores address of first node of queue liked list
struct node * link; // link to next node of linked list
};

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

public class NQues {
public List<Integer>[] ques;
public NQues(int n){
ques = (ArrayList<Integer>[])new ArrayList[n];
for(int p=0;p<n;p++){
ques[p]=new ArrayList<Integer>();
}}

public void insert(int data, int queNum){
if(queNum>ques.length)
System.out.println("System has less than "+queNum+" Ques. Please enter valid Queue number");
ques[queNum-1].add(data);
}

public int peek(int queNum){
if(ques[queNum-1].size()==0){
System.out.println("Queue "+queNum+ " is empty");
return -1;
}
return ques[queNum-1].get(0);
}

public int poll(int queNum){
if(ques[queNum-1].size()==0){
System.out.println("Queue "+queNum+ " is empty");
return -1;
}
return ques[queNum-1].remove(0);
}

public int size(int queNum){
return ques[queNum-1].size();
}
}

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

Head{
Node* next; //push O(1)
Node* last; //pop O(1)
}
Node {
Node* next;
}
I will have linklist of Head and where each head will maintain the linklist of Node.

- iictarpit September 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

I will consider this problem as a hashTable implementation, where we can imagine each hashed key will act as a head of n queues and linear chaining will represent data structure of each queue.
To solve this problem, i will use a hashing function which will convert all the keys(data) to n hashed values(n buckets) using the very basic concept of collision resolution in HashTable. For each hashed key collision, i will add value in a chain(queues) in relevant bucket out of those n buckets. I will also keep loading factor to be 90%.

- Shishir September 03, 2012 | 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