Amazon Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
Some questions needs to be asked --- Are both expected to consume the same amount of space? (It may be desirable that a different parking lot or a different level or a selected area be designated for Motorcycle parking).
Other important point that needs consideration are duration of parking and payment, Type of parking spot (Regular, Valet or for Handicapped - More classes can be added).
1. Create a class for the vehicle:
2. Create a HashMap:
- A January 10, 2013HashMap<Vehicle, Integer> parkDetail = new HashMap<Vehicle, Integer>();
where the second Integer field is the parkingspot ID.
//This HashMap will keep the details of the occupied parking slots.
3. Create a Queue of Integer which will be used to track the free parking spots, when a parking spot gets free...add it to the queue....If a new vehicle has come den remove the corresponding entry from this queue and add it to hashMap.
For 4 wheeler and 2 wheeler, we can maintain two copies of HashMap and Queue as there will be different parking spots for both.