This question evaluates a candidate's competence in designing efficient stateful data structures and algorithmic optimization for an n×n game implementation, focusing on time-space trade-offs and robust API design.
Implement a class that supports playing an n × n Tic-Tac-Toe game.
Create a class TicTacToe(n) with:
move(row, col, player) -> int
row
and
col
are 0-indexed coordinates.
player
is either
1
or
2
.
(row, col)
(assume the move is always valid and the cell is empty).
0
if there is no winner after this move,
1
if player 1 wins after this move,
2
if player 2 wins after this move.
A player wins if they fill an entire row, column, main diagonal, or anti-diagonal.
2 <= n <= 10^4
(so you should avoid O(n) scanning per move)
move
and
O(n)
space.