Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Find Winner on a Tic Tac Toe Game

XPChallenge Points: 12
levelLevel: Easy

Two players, A and B, play Tic-Tac-Toe on a 3×3 grid. A goes first and places 'X', B places 'O'.
Given moves[i] = [r, c] (0-indexed) as the sequence of valid moves, return:

  • "A" if A wins,

  • "B" if B wins,

  • "Draw" if all 9 cells are filled with no winner,

  • "Pending" otherwise.

A player wins if any row, column, or diagonal has three of their marks.

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"

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result