Build a Tic-Tac-Toe App
Company: Whatnot
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates proficiency in interactive UI development and stateful game logic, including turn management, board state representation, win/draw detection, input validation, and reset flow.
Constraints
- 0 <= len(commands) <= 100000
- The board size is always 3 x 3
- For a valid move command, row and col are intended to be in the range [0, 2]
- Invalid moves into occupied cells or after the game is over must be ignored
- Only successful moves switch the current player
Examples
Input: [(0,0), (1,0), (0,1), (1,1), (0,2)]
Expected Output: (['XXX', 'OO.', '...'], 'Winner: X')
Explanation: X fills the entire top row on the fifth move and wins.
Input: [(0,0), (0,1), (0,2), (1,1), (1,0), (1,2), (2,1), (2,0), (2,2)]
Expected Output: (['XOX', 'XOO', 'OXX'], 'Draw')
Explanation: All 9 cells are filled without any player completing a row, column, or diagonal.
Input: []
Expected Output: (['...', '...', '...'], 'In Progress')
Explanation: No commands means the initial empty board is unchanged.
Input: [(0,0), (0,0), (1,1), (0,1)]
Expected Output: (['XX.', '.O.', '...'], 'In Progress')
Explanation: The second command tries to use an occupied cell, so it is ignored and O keeps the turn for the next valid move.
Input: [(0,0), (1,0), (0,1), (1,1), (0,2), (2,2), "RESET", (2,2), (2,2)]
Expected Output: (['...', '...', '..X'], 'In Progress')
Explanation: After X wins, further moves are ignored until RESET. The reset clears the board, then X places one mark at the bottom-right.
Input: [(0,0), (1,1), (0,1), (1,0), (2,2), (1,2)]
Expected Output: (['XX.', 'OOO', '..X'], 'Winner: O')
Explanation: O completes the middle row on the last move.
Hints
- Track four pieces of state: the board, the current player, the current status, and whether the game is over.
- After placing a mark at (row, col), you only need to check that row, that column, and possibly the two diagonals.