Quick Overview

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.

Build a Tic-Tac-Toe App

Company: Whatnot

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement a simple Tic-Tac-Toe mobile app that can be completed in a 45-minute coding interview. Requirements: - Display a 3x3 board. - Support two local players, `X` and `O`, taking alternating turns. - A player can place a mark only in an empty cell. - After every move, detect whether either player has won by completing a row, column, or diagonal. - Detect a draw when the board is full and there is no winner. - Prevent additional moves after the game is over. - Show the current game status: current player, winner, or draw. - Provide a reset button to start a new game. Focus on clean state management, readable UI code, and correctness rather than visual polish.

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.

Implement the core game logic behind a simple Tic-Tac-Toe mobile app. Instead of building the UI, you are given a sequence of commands representing player taps and reset actions. Simulate the app exactly as it should behave on a 3x3 board. Rules: - The board starts empty. - Player X always goes first. - Players alternate turns only after a successful move. - A player may place a mark only in an empty cell. - After each successful move, check whether that player completed a row, column, or diagonal. - If the board becomes full with no winner, the game is a draw. - Once the game has a winner or is a draw, further move commands are ignored until a reset happens. - A reset clears the board and starts a new game with X. Return the final board state and the final game status. Use '.' to represent an empty cell in the returned board.

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.

Hints

  1. Track four pieces of state: the board, the current player, the current status, and whether the game is over.
  2. After placing a mark at (row, col), you only need to check that row, that column, and possibly the two diagonals.

Loading coding console...