Bird
0
0

In a parking system, you have enums VehicleType { CAR, BIKE, TRUCK } and SpotType { COMPACT, LARGE, HANDICAPPED }. You want to assign spots such that:

hard📝 Trade-off Q15 of 15
LLD - Design — Parking Lot System
In a parking system, you have enums VehicleType { CAR, BIKE, TRUCK } and SpotType { COMPACT, LARGE, HANDICAPPED }. You want to assign spots such that:
- Cars use COMPACT spots
- Bikes use HANDICAPPED spots
- Trucks use LARGE spots

Which design approach best ensures no invalid spot assignment happens?
AUse a mapping dictionary from VehicleType to SpotType and validate assignments
BUse separate if-else blocks without enums for flexibility
CAssign spots randomly and check later if valid
DUse strings instead of enums for vehicle and spot types
Step-by-Step Solution
Solution:
  1. Step 1: Understand enum benefits for mapping

    Enums provide fixed sets, so mapping ensures clear, valid assignments.
  2. Step 2: Evaluate design options

    Mapping dictionary with enums enforces rules and prevents invalid spots.
  3. Final Answer:

    Use a mapping dictionary from VehicleType to SpotType and validate assignments -> Option A
  4. Quick Check:

    Mapping enums = safe, clear assignments [OK]
Quick Trick: Map enums directly to enforce valid pairs [OK]
Common Mistakes:
MISTAKES
  • Using strings loses type safety
  • Random assignment causes errors
  • If-else without enums is error-prone

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes