Design an efficient Tic-Tac-Toe engine
DatabricksSoftware Engineer · OnsiteLast updated
This question evaluates a candidate's understanding of efficient algorithm design and minimal state management for a Tic-Tac-Toe engine on an n x n board, including constraints such as O(1) time per move and O(n) space.
Design a Tic-Tac-Toe engine on an n x n board. Implement move(row, col, player) -> result where result indicates no winner, player1 wins, player2 wins, or invalid move. Achieve O(
- time per move and O(n) space by maintaining minimal state. Extend the API to support reset() and an optional undo(). Write comprehensive tests for edge cases (repeated moves, out-of-bounds, early wins, and filled board with no winner).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.