Bird
Raised Fist0

Identify the error in this win condition checking function:

medium📝 Analysis Q6 of Q15
LLD - Design — Tic-Tac-Toe Game
Identify the error in this win condition checking function:
def check_column_win(board):
    n = len(board)
    for col in range(n):
        if all(board[col][row] == 'X' for row in range(n)):
            return True
    return False
AThe loop range is incorrect
BThe function does not return a value
CRow and column indices are swapped in board access
DThe all() function is used incorrectly
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the board access pattern

    board[col][row] accesses row-th element of col-th row, which is incorrect for column check.
  2. Step 2: Correct index usage

    It should be board[row][col] to check all rows in a fixed column.
  3. Final Answer:

    Row and column indices are swapped in board access -> Option C
  4. Quick Check:

    Swap indices for column check [OK]
Quick Trick: Use board[row][col] to check columns [OK]
Common Mistakes:
MISTAKES
  • Swapping row and column indices
  • Forgetting return statement
  • Wrong loop range

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes