Bird
Raised Fist0

Given this simplified move validation function for a king:

medium📝 Analysis Q13 of Q15
LLD - Design — Chess Game
Given this simplified move validation function for a king:
def is_valid_king_move(start, end):
    row_diff = abs(start[0] - end[0])
    col_diff = abs(start[1] - end[1])
    return (row_diff <= 1 and col_diff <= 1) and (row_diff + col_diff != 0)

What will is_valid_king_move((4,4), (5,5)) return?
ATrue
BFalse
CNone
DError
Step-by-Step Solution
Solution:
  1. Step 1: Calculate row and column differences

    row_diff = |4 - 5| = 1, col_diff = |4 - 5| = 1
  2. Step 2: Evaluate conditions

    row_diff <= 1 and col_diff <= 1 is True; row_diff + col_diff != 0 is True (1+1=2)
  3. Final Answer:

    True -> Option A
  4. Quick Check:

    King moves one step any direction = True [OK]
Quick Trick: King moves one square in any direction, including diagonals [OK]
Common Mistakes:
MISTAKES
  • Ignoring diagonal moves for king
  • Mistaking zero move as valid
  • Confusing row and column differences

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes