Bird
0
0

Given two strategies: NearestSpotStrategy and RandomSpotStrategy, if the parking lot uses NearestSpotStrategy, what will be the output when a vehicle arrives?

medium📝 Analysis Q4 of 15
LLD - Design — Parking Lot System
Given two strategies: NearestSpotStrategy and RandomSpotStrategy, if the parking lot uses NearestSpotStrategy, what will be the output when a vehicle arrives?
AThe vehicle is assigned a random spot anywhere in the lot.
BThe vehicle is assigned the closest available spot.
CThe vehicle is rejected due to no strategy.
DThe vehicle is assigned the farthest spot.
Step-by-Step Solution
Solution:
  1. Step 1: Identify the active strategy

    The parking lot uses NearestSpotStrategy, so it picks the closest spot.
  2. Step 2: Understand strategy behavior

    NearestSpotStrategy finds the closest free spot to the entrance for the vehicle.
  3. Final Answer:

    The vehicle is assigned the closest available spot. -> Option B
  4. Quick Check:

    NearestSpotStrategy = closest spot [OK]
Quick Trick: Nearest strategy picks closest spot [OK]
Common Mistakes:
MISTAKES
  • Confusing nearest with random
  • Assuming no spot assigned
  • Thinking farthest spot is chosen

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes