Ctrl K

Noughts and Crosses Verdict

Easy
Two people play noughts and crosses on a 3 × 3 board. Player A moves first and places crosses, player B places noughts; they alternate and always pick an empty cell. The game ends as soon as someone has three of their marks in a row, column or diagonal, or when every cell is filled. No moves are made after the game is over. You are given the list moves, where moves[i] = [row, col] is the cell taken on the i-th move (rows and columns are numbered from zero). The moves follow the rules above, and the board starts empty. Return "A" or "B" if that player has won, "Draw" if the board is full with no winner, and "Pending" if the game is not over yet.
Example 1
moves=[[1, 1], [0, 0], [0, 2], [2, 2], [2, 0]] → 'A'

The X marks sit at (1,1), (0,2) and (2,0), the anti-diagonal, so A wins.

Example 2
moves=[[0, 0], [1, 0], [0, 1], [1, 1], [2, 2], [1, 2]] → 'B'

The O marks fill the whole middle row, so B wins.

Example 3
moves=[[2, 1], [0, 1]] → 'Pending'

Only two moves have been made, no line is complete and empty cells remain, so the game goes on.

Constraints
  • 1 ≤ moves.length ≤ 9
  • moves[i].length == 2
  • 0 ≤ row, col ≤ 2
  • No cell appears in moves twice
  • No moves follow a win
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsRows That Match Columns MediumRepack the Tray EasyMirror and Negate a Bitmap EasySwap Rows and Columns EasyPawns the Rook Can Take Easy
loading Python…
Input
moves=[[1, 1], [0, 0], [0, 2], [2, 2], [2, 0]]
Expected
'A'

Run checks the first 3 tests in your browser. Submit checks all 87 tests on the server, hidden ones included.