All problems
0961EasyArrayHash TableMatrixSimulation

Who Comes Out Ahead on the Three-by-Three

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1275Find Winner on a Tic Tac Toe Game

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

Two players take turns marking cells of a three-by-three board, the first player writing "A" and the second "B". The plays are given in order as moves, each [row, column], with the first entry being the first player's opening mark.

A player wins the moment they hold all three cells of any row, any column, or either of the two long diagonals, and the game stops there.

Return "A" or "B" for the winner, "Draw" when the board fills with no winner, or "Pending" when the game is unfinished.

Examples

Example 1

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

The first player takes the whole top row on their third mark, which wins.

Example 2

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

The first player's three marks run down the long diagonal from the top left.

Example 3

Input
moves = [[0, 0], [1, 1]]
Output
"Pending"

Only two marks have been made, so the game is still going.

Constraints

  • 1 <= moves.length <= 9
  • moves[i].length == 2
  • 0 <= moves[i][0] <= 2
  • 0 <= moves[i][1] <= 2
  • No cell is played twice
  • The plays follow the rules of the game

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def tictactoe(moves: list[list[int]]) -> str:
Java
public String tictactoe(int[][] moves)
September 7
Apply