Skip to content

Practice Find Winner on a Tic Tac Toe Game

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#1275
LeetCode Problem

Find Winner on a Tic Tac Toe Game

Problem Statement

On an initially empty 3 by 3 grid, players A and B alternate moves, with A first. A places X and B places O in an empty cell. A player wins by filling an entire row, column, or diagonal with their mark; a full board without a winner is a draw. No moves follow the end of a game. The valid sequence moves contains [row, column] pairs. Return "A" or "B" for a winner, "Draw" for a completed draw, or "Pending" if play can continue.

Source: Find Winner on a Tic Tac Toe Game on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
moves = [[0,0],[2,0],[1,1],[2,1],[2,2]]
Output
"A"

# Example 2

Input
moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]
Output
"B"

# Example 3

Input
moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]
Output
"Draw"

Constraints

1 <= moves.length <= 9
moves[i].length == 2
0 <= rowi, coli <= 2
There are no repeated elements on moves.
moves follow the rules of tic tac toe.

Related LeetCode Problems

Practice more problems similar to Find Winner on a Tic Tac Toe Game.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.