Bird
0
0

Identify the bug in this check detection function:

medium📝 Analysis Q6 of 15
LLD - Design — Chess Game
Identify the bug in this check detection function:
def is_check(board, king_pos):
    for pos in board:
        if board[pos] == 'queen' and can_attack(pos, king_pos):
            return True
    return False
ALooping over board keys instead of pieces
BMissing parentheses in return statement
CNot checking for all enemy pieces
DUsing wrong variable name for king position
Step-by-Step Solution
Solution:
  1. Step 1: Review piece checks in loop

    The function only checks queens, ignoring other enemy pieces that can cause check.
  2. Step 2: Understand impact on check detection

    Ignoring other pieces causes false negatives in check detection.
  3. Final Answer:

    Not checking for all enemy pieces -> Option C
  4. Quick Check:

    Check detection must consider all enemy pieces [OK]
Quick Trick: Check all enemy pieces, not just queens [OK]
Common Mistakes:
  • Checking only one piece type
  • Assuming queens are only threat
  • Ignoring other piece attacks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes