Tic-Tac-Toe Game – Low Level Design Interview Practice
Practise the Tic-Tac-Toe Game low level design problem the way an LLD round actually runs. You are asked for requirements first, then a class model, and then to extend the design when a new requirement lands part way through – the follow-up that separates a design that was memorised from one that was understood.
The round checks the things interviewers grade: whether your classes carry single responsibilities, whether you reached for a design pattern or reinvented one, whether the design absorbs a new requirement without rewriting what exists, and whether you can explain a trade-off out loud. Feedback covers class modelling, SOLID principles, use of patterns, extensibility and communication.
What this question is really testing
The warm-up question. It is graded on whether you generalise cleanly to N x N and keep win detection out of the board, not on whether it works.
Requirements to establish first
- An N x N board, usually 3x3, with two players alternating.
- Reject a move onto an occupied cell or outside the board.
- Detect a win on a row, column or either diagonal.
- Detect a draw when the board fills with no winner.
- Report the game state after every move.
Core classes
- Board – The grid and what is in each cell. It knows occupancy, not victory.
- Player – Name and symbol - or a piece type, if you want to allow more than X and O.
- Game – Turn order, move validation and the end condition.
- WinningStrategy – Given a board and the last move, is the game over?
Design patterns that apply
- Strategy – Win detection, so a 3x3 three-in-a-row and an N x N k-in-a-row are two implementations rather than one method with a flag.
- Factory – Only if you support bot players of different difficulty. Otherwise say it is not needed - restraint reads better than a pattern with no job.
Follow-up questions to expect
- Generalise to N x N where k in a row wins. Which of your classes changes?
- Make win detection O(1) per move instead of scanning the board. What do you keep, and what does that cost in memory?
- Add a bot. Where does it plug in without Game knowing it is not a human?
Where candidates lose marks
- Hard-coding 3 throughout, which the first follow-up exposes immediately.
- Win checking inside Board, which is the single most common structural slip on this question.
- Scanning all rows, columns and diagonals after every move when only the last move's lines can have changed.