← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Design a TicTacToe class for an n x n board.
Two players take turns placing marks on the board. Player 1 plays first. Implement:
TicTacToe(int n) — initialise an n x n empty board.move(int row, int col, int player) -> int — record player (1 or 2) playing at (row, col). Moves are guaranteed to be on empty cells. Returns:
0 if no winner yet1 if player 1 just won2 if player 2 just wonA player wins by placing n of their marks in any horizontal, vertical, or one of the two diagonal lines.
Bonus: the move check must run in O(1) per call (no full board scan).
Examples:
n = 3 move(0,0,1) -> 0 move(0,1,2) -> 0 move(1,0,1) -> 0 move(1,1,2) -> 0 move(2,0,1) -> 1 (player 1 fills column 0)
Follow-up Questions:
k-in-a-row on an n x n board?