## Amazon Interview Question for Software Engineer / Developers

- 0of 0 votes

AnswersThere are different buildings in one environment, each with machines that can handle one request at a time. How would you design the request handling so that there is no single fail-point and is scalable.

- JSDUDE April 08, 2013 in United States

Hint: It is ok if a request is sent to a machine that is already servicing another request. We can handle requests that come back from a machine. But he didnot want a lock on a single file that contained the data of empty machines

Follow up question was, lets say BLDG-A has 250 free machines, BLDG-B has 500 free machines, BLDG-C has 100 free machines and BLDG-D has 0. How would you assign requests? What if you had 850 requests at the same time? Why would you assign what you did?| Report Duplicate | Flag | PURGE

Amazon Software Engineer / Developer Distributed Computing

**Country:**United States

**Interview Type:**Phone Interview

#include <iostream>

#include <conio.h>

using namespace std;

class Node{

public:

void set_next(Node* next_node){Next_Node = next_node;}

Node * get_next(){return Next_Node;}

char * get_name(){return nod_name;}

void set_objects(int,int);

void set_name(char*);

int get_objects(int);

void set_sum(int sums){sum = sums;}

int get_sum(){return sum;}

~Node(){};

private:

int sum;

char *nod_name;

int objects[6];

Node * Next_Node;

};

void Node::set_name(char* name){

nod_name = new char[strlen(name+1)];

strcpy(nod_name,name);

}

void Node::set_objects(int obj,int indux)

{

objects[indux] = obj;

}

int Node::get_objects(int indux)

{

return objects[indux];

}

class List{

public:

List();

void sort(Node*,int);

void display(int);

void get_input(int,Node*);

int get(int);

void add(int[],Node*);

private:

int size;

Node * Head_Node;

Node * Current_Node;

Node * Last_Current_Node;

};

List::List()

{

size = 0;

Head_Node = new Node();

Head_Node->set_next(NULL);

Current_Node = NULL;

Last_Current_Node = NULL;

}

void List::sort(Node * sort_node, int number_nodes)

{

char temp_name[25];

Current_Node = Head_Node;

int * sum = new int[number_nodes];

for(int i=0;i<number_nodes;i++)

{

sum[i] = 0;

if(Current_Node != NULL)

{

for(int a=0;a<6;a++)

{

sum[i] += this->Current_Node->get_objects(a);

}

}

Current_Node->set_sum(sum[i]);

Current_Node = Current_Node->get_next();

}

Current_Node = Head_Node;

Last_Current_Node = Head_Node->get_next();

int temp = 0;

for(int i=0;i<number_nodes;i++)

{

for(int a=0;a<number_nodes;a++)

{

if(Current_Node != NULL && Last_Current_Node != NULL)

{

if(Current_Node->get_sum() < Last_Current_Node->get_sum())

{

temp = Current_Node->get_sum();

strcpy(temp_name , Current_Node->get_name());

Current_Node->set_sum(Last_Current_Node->get_sum());

Current_Node->set_name(Last_Current_Node->get_name());

Last_Current_Node->set_sum(temp);

Last_Current_Node->set_name(temp_name);

}

Last_Current_Node = Last_Current_Node->get_next();

}

else

{

break;

}

}

Last_Current_Node = Head_Node;

Current_Node = Current_Node->get_next();

}

}

void List::display(int number_nods)

{

Current_Node = Head_Node;

if(Current_Node != NULL)

{

cout" List Size = "sizeendl;

coutendl;

for(int a=0;a<number_nods;a++)

{

cout" Element "" "a+1" "Current_Node->get_name()endl;

Current_Node = Current_Node->get_next();

}

coutendl;

}

}

void List::get_input(int number_nod,Node * Nodes)

{

int f = 0;

char arrs[25];

for(int i=0;i<number_nod;i++)

{

int arr[6] = {0};

cout"Enter The Name OF the Node: ";

cin>>arrs;

Nodes[i].set_name(arrs);

for(int a=0;a<6;a++)

{

f = 0;

cout"Enter Value "a+1": ";

cin>>arr[a];

for(int j=0;j<6;j++)

{

if(arr[a] == arr[j])

{

f++;

}

}

if(f > 1)

{

cout"Dublicate Value Within One Node Is Not Allowed "endl;

a--;

continue;

}

}

cout"Node Values Finshed"endlendl;

this->add(arr,&Nodes[i]);

}

}

int List::get(int Indux)

{

return Current_Node->get_objects(Indux);

}

void List::add(int objests[],Node * nodss)

{

for(int i=0;i<6;i++)

{

nodss->set_objects(objests[i],i);

}

if(Current_Node == NULL)

{

nodss->set_next(NULL);

Head_Node->set_next(nodss);

Last_Current_Node = Head_Node;

Current_Node = nodss;

Head_Node = Current_Node;

}

else

{

nodss->set_next(Current_Node->get_next());

Current_Node->set_next(nodss);

Last_Current_Node = Current_Node;

Current_Node = nodss;

}

size++;

}

int main()

{

List list;

int number_nods = 0;

cout"How many Nodes You want to Create ? ";

cin>>number_nods;

coutendl;

Node * Nodes = new Node[number_nods];

list.get_input(number_nods,Nodes);

list.sort(Nodes,number_nods);

list.display(number_nods);

delete [] Nodes;

system("pause");

}

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

I feel this question involves pseudo implementation of a load balancer

- Anonymous September 30, 2014Shouldn't a cluster of two nodes handle the fault tolerent system.