bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1275. Find Winner on a Tic Tac Toe Game

1275. Find Winner on a Tic Tac Toe Game

Leetcode Solutions

Approach: Record Each Move

  1. Initialize two arrays rows and cols of size 3 to zero, representing the sum of values in each row and column.
  2. Initialize two variables diag and anti_diag to zero, representing the sum of values in the diagonal and anti-diagonal.
  3. Iterate over the moves array, alternating between player A and B (starting with A).
  4. For each move [row, col], add the player's value to rows[row] and cols[col].
  5. If the move is on the diagonal (row == col), update diag.
  6. If the move is on the anti-diagonal (row + col == 2), update anti_diag.
  7. After each move, check if the absolute value of rows[row], cols[col], diag, or anti_diag is 3. If so, the current player wins.
  8. If all moves are played and no winner is found, check if the game is a 'Draw' or 'Pending'.
UML Thumbnail

Approach: Brute Force

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...
bugfree Icon
OR