Problem details
A parking lot is a designated area for parking vehicles, commonly found at venues like malls, stadiums, and offices. It has a fixed number of spots for different vehicle types, with charges based on parking duration. Time is tracked via a ticket issued at entry, and payment can be made at exit via card or cash.
Expectations from the interviewee:
- Vehicle types: Handling different vehicle types—car, truck, van, motorcycle—which can have the following set of questions
- How will capacity be allocated for different vehicle types?
- If the parking spot of any vehicle type is booked, can a vehicle of another type park in the designated parking spot?
- Parking spot type: Another important area of discussion that the interviewer may expect you to be familiar with is the different types of parking spots—such as handicapped, compact, large, and motorcycle spots. Here are some key questions you might consider:
- How will the parking capacity for each type of spot be determined?
- What should happen when a particular section of the parking lot becomes full?
- How can the system efficiently track available parking spots across multiple floors if the lot has more than one level?
- How will the parking spots be allocated among the four different types within the lot?
- Payment flexibility: The payment structure is a crucial aspect of the parking lot system. The interviewer may expect you to consider questions such as:
- How can customers pay at different exit points using various methods (cash, credit, coupon)?
- In a multi-floor parking lot, how will the system track if a customer has already paid on a specific floor rather than at the exit?
- Pricing: To clarify the pricing model, you might ask:
- How will pricing be structured? Should we implement different rates by the hour, like $4 for the first hour, $3.5 for the next two hours, and $2.5 for each additional hour?
- Will the pricing differ based on vehicle type?
- Design approach: We'll design the parking lot system using a bottom-up approach:
- Start by designing the smallest components, such as vehicle and parking spot types.
- Use these to build larger components, like the payment system at the exit.
- Continue this process until the entire system, including the parking lot, is designed.
- Design pattern:
Requirements:
- R1: The parking lot must accommodate up to 5,000 vehicles.
- R2: There are four types of parking spots: handicapped, compact, large, and motorcycle.
- R3: The parking lot should have multiple entry and exit points.
- R4: Four types of vehicles are allowed: car, truck, van, and motorcycle.
- R5: A display board should show available spots for each parking spot type.
- R6: The system should prevent additional vehicles from entering if the lot reaches its 5,000 vehicle capacity.
- R7: If the lot is full, the entrance and display board should show a "full" message.
- R8: Customers should receive a parking ticket at the entrance and pay at the exit.
- R9: Payments can be made at an automated exit panel or to a parking agent.
- R10: Charges should be based on an hourly rate.
- R11: Payments can be made by credit/debit card or cash.