Tap here to switch tabs
Problem
Submissions

Problem: Find Winner on a Tic Tac Toe Game

med
30 min
Try to solve the Find Winner on a Tic Tac Toe Game problem.

Statement

Tic Tac Toe is played on a 3imes33 imes 3 grid with two players, A and B. Player A always moves first and places an 'X' mark, while player B moves second and places an 'O' mark.

Players take turns placing their respective characters into any empty square on the board. The game concludes when a player places 33 of their marks in a row, column, or diagonal, resulting in a win for that player. If all 99 squares are filled and no player has achieved 33 marks in a line, the game ends in a draw. If empty squares remain and no player has won, the game is still ongoing.

Given a 2extD2 ext{D} integer array moves where moves[i] = [row_i, col_i] indicates that the iextthi^{ ext{th}} move was made at grid position (row_i, col_i), return:

  • "A" if player A wins the game.

  • "B" if player B wins the game.

  • "Draw" if the game ends in a draw.

  • "Pending" if the game is still in progress.

Constraints:

  • 1≤1 \leq moves.length ≤9\leq 9

  • moves[i].length =2= 2

  • 0≤0 \leq row_i, col_i ≤2\leq 2

  • There are no repeated elements on moves.

  • moves follow the rules of tic tac toe.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Winner on a Tic Tac Toe Game

med
30 min
Try to solve the Find Winner on a Tic Tac Toe Game problem.

Statement

Tic Tac Toe is played on a 3imes33 imes 3 grid with two players, A and B. Player A always moves first and places an 'X' mark, while player B moves second and places an 'O' mark.

Players take turns placing their respective characters into any empty square on the board. The game concludes when a player places 33 of their marks in a row, column, or diagonal, resulting in a win for that player. If all 99 squares are filled and no player has achieved 33 marks in a line, the game ends in a draw. If empty squares remain and no player has won, the game is still ongoing.

Given a 2extD2 ext{D} integer array moves where moves[i] = [row_i, col_i] indicates that the iextthi^{ ext{th}} move was made at grid position (row_i, col_i), return:

  • "A" if player A wins the game.

  • "B" if player B wins the game.

  • "Draw" if the game ends in a draw.

  • "Pending" if the game is still in progress.

Constraints:

  • 1≤1 \leq moves.length ≤9\leq 9

  • moves[i].length =2= 2

  • 0≤0 \leq row_i, col_i ≤2\leq 2

  • There are no repeated elements on moves.

  • moves follow the rules of tic tac toe.