Design Tic-Tac-Toe
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Two players take turns placing marks on an n x n board. A player wins by filling an entire **row**, an entire **column**, the **main diagonal** (top-left to bottom-right), or the **anti-diagonal** (top-right to bottom-left) with their marks.
- TicTacToe(n) creates an empty n x n board.
- move(row, col, player) places player's mark (player is 1 or 2) at the empty cell (row, col). Return player if this move wins the game, otherwise 0.
Every move targets an empty cell inside the board, and no moves are made after someone has won. Aim for O(1) time per move instead of rescanning the board.
Examples
Constraints
- `1 <= n <= 100`
- `player` is `1` or `2`.
- `0 <= row, col < n`, and every move is on an empty cell.
- No `move` is called after a player has won; at most `n^2` calls.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.