Tic-tac-toe referee in O(1) per move
Write a class TicTacToe(n) that referees a game of tic-tac-toe on an n × n board between players 1 and 2.
move(row, col, player)putsplayer's mark on the cell atrow,col(0-indexed) and returnsplayerif that gives them a whole row, a whole column or one of the board's two diagonals; otherwise it returns0.
Every move is valid: it lands on an empty cell inside the board, and none comes after a win. Players don't have to alternate. move must take O(1) time, so rescanning the n cells of a line after each move is too slow.
The tests call the provided run_game(n, moves): it builds the referee, plays each [row, col, player] in order and returns the list of results.
Besides the tests, one large input (a 2,500 × 2,500 board, 10,000 moves) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
run_game(3, [[1,1,1],[0,0,2],[1,0,1],[2,2,2],[1,2,1]])→[0,0,0,0,1]run_game(3, [[0,0,1],[0,2,2],[1,0,1],[1,1,2],[2,2,1],[2,0,2]])→[0,0,0,0,0,2]run_game(1, [[0,0,2]])→[2]