Amazon Interview Question for Software Engineer / Developers


Team: AWS
Country: United States
Interview Type: Phone Interview




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

A class "ParkingLot" would be an aggregate of "ParkingSpot".
The other main class would be the "ParkingEntryGate" at which you need collect a "Ticket".
The ParkingEntryGate would maintain the details of the "Vehicle" and the time in.
Another good feature would be a "FreeParkingSpotBillboard" which notifies people as to which parking spots are free. The "ParkingSpot" would be associated with a unique id.
Another Entity would be the "Customer" who has a "Vehicle" and a "Ticket". There would be a method named GetCustomerDetails inside "ParkingLot" which would tell us the details of time spent inside parking for each customer by date. Every customer would have a unique id.
Basically one needs to conceptualize the various entities and make a domain driven design.
(This could be used at the Parking Entry Gate with a front end of a web application if required.)

- quickpuzzlesolver December 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Watch "Mission Impossible: Ghost protocol" ending part
for a reasonably good design. Btw, the movie rocks!

- kartikaditya December 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

any more?

class ParkingLot
{
private:
    string name;
    string address;
    int Capacity;
    int Used;

public:
    // how many spaces left in the parkinglot
    int GetSpaces();

    // how many spaces left 
    // enum {compact = 0, mid, ...}
    int GetSpaces(int size);

    // total spaces parkinglot has
    int GetCapacity();

    // if the parkinglot is opened
    bool IsOpened();

    // return parkinglot open time of a specified date
    // e.g. "8:00 AM - 10:00 PM"
    string GetOpenTime(time_t date); 

    // fee $ per hour
    int ChargeMoney();

    // Get the address of parking lot
    string GetAddress();

    // get type of parkinglot
    // enum { outdoor = 0, ... };
    int GetType();

    string Name();
};

- Anonymous December 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

My solution (Didnt take time into consideration but can take it into consideration as a part of Vehicle class and calculating it in between the parkVehicle() and releaseVehicle() classes :

public class ParkingLot 
{
	Vector<ParkingSpace> vacantParkingSpaces = null;
	Vector<ParkingSpace> fullParkingSpaces = null;
	
	int parkingSpaceCount = 0;
	
	boolean isFull;
	boolean isEmpty;
	
	ParkingSpace findNearestVacant(ParkingType type)
	{
		Iterator<ParkingSpace> itr = vacantParkingSpaces.iterator();
		
		while(itr.hasNext())
		{
			ParkingSpace parkingSpace = itr.next();
			
			if(parkingSpace.parkingType == type)
			{
				return parkingSpace;
			}
		}
		return null;
	}
	
	void parkVehicle(ParkingType type, Vehicle vehicle)
	{
		if(!isFull())
		{
			ParkingSpace parkingSpace = findNearestVacant(type);
		
			if(parkingSpace != null)
			{
				parkingSpace.vehicle = vehicle;
				parkingSpace.isVacant = false;
			
				vacantParkingSpaces.remove(parkingSpace);
				fullParkingSpaces.add(parkingSpace);
				
				if(fullParkingSpaces.size() == parkingSpaceCount)
					isFull = true;
				
				isEmpty = false;
			}
		}
	}
	
	void releaseVehicle(Vehicle vehicle)
	{
		if(!isEmpty())
		{
			Iterator<ParkingSpace> itr = fullParkingSpaces.iterator();
			
			while(itr.hasNext())
			{
				ParkingSpace parkingSpace = itr.next();
				
				if(parkingSpace.vehicle.equals(vehicle))
				{
					fullParkingSpaces.remove(parkingSpace);
					vacantParkingSpaces.add(parkingSpace);
					
					parkingSpace.isVacant = true;
					parkingSpace.vehicle = null;
					
					if(vacantParkingSpaces.size() == parkingSpaceCount)
						isEmpty = true;
					
					isFull = false;
				}
			}
		}
	}
	
	boolean isFull()
	{
		return isFull;
	}
	
	boolean isEmpty()
	{
		return isEmpty;
	}
}

public class ParkingSpace 
{
	boolean isVacant;
	Vehicle vehicle;
	ParkingType parkingType;
	int distance;
}

public class Vehicle 
{
	int num;
}

public enum ParkingType
{
	REGULAR,
	HANDICAPPED,
	COMPACT,
	MAX_PARKING_TYPE,
}

- Srikant Aggarwal December 25, 2011 | 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