I just started coding without really syncing with the interviewer on the approach first.
Start by clarifying requirements and constraints, then design a scalable data model and win-checking algorithm. Discuss trade-offs between different approaches and consider extensibility for future features.
Pro tip: Emphasize that the win condition is always 3 consecutive marks, so you can optimize by only checking lines through the last move, reducing time complexity from O(n^2) to O(1) per move.
Ask about board size limits, number of players, move validation, and expected game status responses. Confirm if players can choose symbols and if the game supports undo or replay.
Represent the board as a 2D array or hash map, track player positions, and maintain game status. Consider using a move history for undo functionality.
After each move, check only lines (horizontal, vertical, diagonal) passing through the placed mark for 3 consecutive same symbols. This ensures O(1) time per move.
Return status: ongoing, win (with player), or draw. Handle invalid moves, full board, and multiple winners (if simultaneous, though unlikely with sequential moves).
Compare approaches: full board scan vs. incremental check. Discuss memory vs. time, and how to extend for larger boards or more players.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.