Bird
Raised Fist0

What is the logical error in this method for checking parking spot availability?

medium📝 Analysis Q6 of Q15
LLD - Design — Parking Lot System
What is the logical error in this method for checking parking spot availability?
boolean isSpotAvailable(int spotNumber) { return spotNumber == 0; }
AIt incorrectly returns true only when spotNumber is zero, not checking actual availability
BIt correctly checks if the spot number is valid
CIt returns false for spot number zero which is always available
DIt throws an exception for invalid spot numbers
Step-by-Step Solution
Solution:
  1. Step 1: Analyze method logic

    The method returns true only if spotNumber equals zero, which is unrelated to availability.
  2. Step 2: Identify correct behavior

    Availability should be checked against spot occupancy, not spot number value.
  3. Final Answer:

    It incorrectly returns true only when spotNumber is zero, not checking actual availability -> Option A
  4. Quick Check:

    Check if method checks occupancy status, not spot number [OK]
Quick Trick: Availability depends on occupancy, not spot number [OK]
Common Mistakes:
MISTAKES
  • Assuming spot number zero means available
  • Confusing spot number with availability status
  • Ignoring actual occupancy data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes