Bird
Raised Fist0

What will be the output of this code snippet?

medium📝 Analysis Q5 of Q15
LLD - Design — Tic-Tac-Toe Game
What will be the output of this code snippet?
def check_diagonal_win(board):
    n = len(board)
    if all(board[i][i] == 'O' for i in range(n)):
        return True
    return False

board = [['O','X','X'],['X','O',''],['X','','O']]
print(check_diagonal_win(board))
ATrue
BFalse
CNone
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand diagonal check logic

    The function checks if all elements from top-left to bottom-right are 'O'.
  2. Step 2: Verify board diagonal elements

    board[0][0] = 'O', board[1][1] = 'O', board[2][2] = 'O', so condition is True.
  3. Final Answer:

    True -> Option A
  4. Quick Check:

    Diagonal all 'O' returns True [OK]
Quick Trick: Diagonal check uses indices i,i [OK]
Common Mistakes:
MISTAKES
  • Checking wrong diagonal
  • Using wrong indices
  • Assuming False due to other cells

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes