Amazon Interview Question for Software Engineer / Developers


Country: India




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

4S 2M 1L

#define uint Token

struct item
{
char data/maal[];
};

class Compartment
{

int space = 10;
int count = 0;//initially no items / empty compartment

public :

Compartment()
{
space = 10;
count = 0;
}

/*bool open()
{return true;}
void close()
{}*/

void push_item(Item i1)
{
if( count < space )
{
item[count++] = i1;
}
}
Item pop_item()
{
if( count > 0 )
{
count--;
return item[count];
}
}
bool isSpaceAvailable()
{
return( count < space )
}
Item item[10+1];//Assuming one compartment can hold 10 items

};

class SmallCompartment : public Compartment
{

};

class MediumCompartment : public Compartment
{
SmallCompartment c1, c2;
public :
bool isSpaceAvailable()
{
return c1.isSpaceAvailable() || c2.isSpaceAvailable()
}
};

LargeCompartment : public Compartment
{
MediumCompartment m1, m2;
public :
bool isSpaceAvailable()
{
return m1.isSpaceAvailable() || m2.isSpaceAvailable()
}
};


CloakRoom
{
uint itemCount = 0;//This tells whether there are items available in cloak room or not

//Assume there are few Small, Medium, Large size compartments in a cloak room
uint SmallCompartmentCount = 5;
uint MediumCompartmentCount = 3;
uint LargeCompartmentCount = 2;

//Assume there are few Small, Medium, Large size compartments in a cloak room
TArray<SmallCompartment, SmallCompartmentCount> SmallCompartments;
TArray<MediumCompartment, MediumCompartmentCount> MediumCompartments;
TArray<LargeCompartment, LargeCompartmentCount> LargeCompartments;
public:
Token# put_item(Item i)
{
if( SmallCompartments.isSpaceAvailable() )
{
itemCount++;
return SmallCompartments.Add( i );//Assuming we are returning TArray index here as Token#
}
else if( MediumCompartments.isSpaceAvailable() )
{
itemCount++;
return MediumCompartments.Add( i );
}
else if( LargeCompartments.isSpaceAvailable() )
{
itemCount++;
return LargeCompartments.Add( i );
}
return -1;
}
Item get_item(Token tokenNo)
{
if( SmallCompartments.find(tokenNo) )
{
itemCount--;
return SmallCompartments.Remove[tokenNo];
}
else if( MediumCompartments.find(tokenNo) )
{
itemCount--;
return MediumCompartments.Remove[tokenNo];
}
else if( LargeCompartments.find(tokenNo) )
{
itemCount--;
return LargeCompartments.Remove[tokenNo];
}
return NULL;
}
bool isSpaceAvailable()
{
return SmallCompartments.isSpaceAvailable() || MediumCompartments.isSpaceAvailable() || LargeCompartments.isSpaceAvailable();
}

//This indicates that there is some item available in cloak room
bool isItemAvailable()
{
return (itemCount > 0);
}

};

void main()
{
CloakRoom cr;
if( cr.isSpaceAvailable() )
{
cout << "How may I help you." << endl;
Item item1;
item1.data = "Jalebi";
Token tok = cr.put_item(item1);//Add item to cloak room
}
if ( cr.isItemAvailable )
{
Item item = cr.get_item( tok );//Take item from cloak room
}
}//end main

- SantoshRameshraoDeshmukh February 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

could somebody please explain the question in a bit more detailed way.... wat actually we have to do....

- asp January 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what is it that you didn't understand

- P January 24, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Yeah me also confused

- Not January 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

this is not something to close, since we don't have proper info.. assume the best.. and give the design that can do stuff.

Optimizing the code has to be written in the cloak room, which calls add, remove items and optimizes the space.

public class Item{
static int count = 0;

public Item(String name,int storage){
this.name = name;
this.storage = storage;
this.id = count;
count++;
}
string name;
int id;
int storage;

int getStorage(){
return storage;
}

int getId(){}
}

public class Compartment{
public Compartment(int s){
capacity = s;
}
int capacity;
int filled = 0;

List<Items> items;

bool isSpaceAvailable(){

}

bool addItem(Item item){
return true; // if space available
else return false;
}

Item deleteItem(int id){

}
}

public class CloakRoom{
Compartment one(1),two(2),three(3);
// in order to implement small, medium, large -- enum can be used.
}

- Mr.B January 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

An interface Compartment, implemented by 3 types of compartment (Small, Medium, Large)
A class CloakRoom, which contains a reference of Compartment.
A System containing a collection of CloakRoom objects.

Not sure about how optimization can be brought into picture. Can someone help on this?

- Learner January 25, 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