A mobile gaming platform runs real-time Tic-Tac-Toe tournaments with millions of daily users. To keep latency low, the backend needs to evaluate each move in constant time without scanning the whole board.
You are given an n x n Tic-Tac-Toe board (initially empty) and a list of moves. Each move is a triple (row, col, player) where player is 1 or 2.
After each move, return:
0 if nobody has won yet1 if player 1 wins on that move2 if player 2 wins on that moveIf a move is invalid, you must raise ValueError:
row or col not in [0, n-1])player is not 1 or 2Implement the function:
tictactoe_move_results(n: int, moves: list[list[int]]) -> list[int | str]Return a list of results aligned with the moves. If a move raises ValueError, place the string "ValueError" at that position and stop processing further moves (this matches the platform’s “reject the request” behavior).
Example 1
n = 3, moves = [[0,0,1],[0,2,2],[2,2,1],[1,1,2],[2,0,1],[1,0,2],[2,1,1]][0, 0, 0, 0, 0, 0, 1]Example 2
n = 2, moves = [[0,0,2],[1,1,2]][0, 2]n.1 <= n <= 10^50 <= moves.length <= n^2[row, col, player] with integers