Bird
Raised Fist0

Which of the following code snippets correctly checks a row for a win in a 3x3 tic-tac-toe board represented as a 2D array board?

easy🧠 Conceptual Q12 of Q15
LLD - Design — Tic-Tac-Toe Game
Which of the following code snippets correctly checks a row for a win in a 3x3 tic-tac-toe board represented as a 2D array board?
Aif board[row][0] != board[row][1] != board[row][2]:
Bif board[0][row] == board[1][row] == board[2][row] != None:
Cif board[row][0] == board[row][1] == board[row][2] != None:
Dif board[0][0] == board[1][1] == board[2][2] != None:
Step-by-Step Solution
Solution:
  1. Step 1: Identify row checking syntax

    Checking a row means comparing all elements in the same row index but different columns.
  2. Step 2: Match code to row check

    if board[row][0] == board[row][1] == board[row][2] != None: compares board[row][0], board[row][1], and board[row][2], which is correct for a row check.
  3. Final Answer:

    if board[row][0] == board[row][1] == board[row][2] != None: -> Option C
  4. Quick Check:

    Row check = compare same row elements [OK]
Quick Trick: Row check compares same row, different columns [OK]
Common Mistakes:
MISTAKES
  • Mixing row and column indices
  • Using != instead of == for equality
  • Checking diagonal instead of row

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes