Design Tic-Tac-Toe
Design a TicTacToe class for an n x n board. move(row, col, player) records that the given player (1 or 2) placed a mark at that empty cell and returns the id of the player who wins after that move, or 0 if there is no winner yet. A player wins by filling any full row, full column, or either diagonal with their marks. Assume all moves are valid and target empty cells.
Open official problem prompt ↗Report the winner immediately after each move on an n x n Tic-Tac-Toe board without scanning the board.
Like a scoreboard that tracks each row and column's net lean toward player 1 or player 2 - the moment any line leans fully one way (all n cells), the game is over.
- Input
- n = 3; moves = [(0,0,1),(0,2,2),(2,2,1),(1,1,2),(2,0,1),(1,0,2),(2,1,1)]
- Output
- [0, 0, 0, 0, 0, 0, 1]
- Why
- After player 1's move at (2,1), row 2 holds player 1's marks at (2,0),(2,1),(2,2), completing a full row of 3.
2 <= n <= 100player is 1 or 21 <= row, col <= nEach cell is used at most once per gameAt most n^2 calls to move