Bird
0
0

Given this simplified code snippet for castling validation, what will be the output if the king has moved before?

medium📝 Analysis Q13 of 15
LLD - Design — Chess Game
Given this simplified code snippet for castling validation, what will be the output if the king has moved before?
def can_castle(king_moved, rook_moved, path_clear):
    if king_moved or rook_moved:
        return False
    if not path_clear:
        return False
    return True

print(can_castle(True, False, True))
ANone
BTrue
CFalse
DError
Step-by-Step Solution
Solution:
  1. Step 1: Analyze input parameters

    king_moved is True, rook_moved is False, path_clear is True.
  2. Step 2: Follow function logic

    Since king_moved is True, the first if condition triggers and returns False immediately.
  3. Final Answer:

    False -> Option C
  4. Quick Check:

    King moved disables castling = False [OK]
Quick Trick: If king moved, castling returns False immediately [OK]
Common Mistakes:
  • Ignoring king_moved condition
  • Assuming path_clear overrides king_moved
  • Expecting True despite king having moved

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes