Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Track Tic-Tac-Toe Scoreboard

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Track Tic-Tac-Toe Scoreboard. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

A mobile game team at NovaPlay wants a simple Tic-Tac-Toe engine that supports gameplay, tracks the running score, and allows resetting either the board or the full match. Implement the core game logic.

Write a function that processes a sequence of commands for a 3x3 Tic-Tac-Toe game. Players alternate as X then O. Valid move commands place the current player's mark on the board. When a player wins, that player's score increases by 1 and the board automatically resets for the next round, starting again with X. A draw also resets the board with no score change. Invalid moves are ignored.

Formal Specification

Input: commands, a list of commands where each command is one of:

  • {"type": "move", "row": int, "col": int}
  • {"type": "reset_board"}
  • {"type": "reset_all"}

Output: a dictionary with:

  • board: final 3x3 board as a list of lists containing "X", "O", or ""
  • current_player: "X" or "O"
  • score: { "X": int, "O": int }

Constraints

  • 1 <= len(commands) <= 10^4
  • Each command is a dictionary with a type field
  • For move commands, row and col are intended to be integers in the range [0, 2]
  • Invalid moves do not change the board, score, or current player
  • After any win or draw, the board resets and the next round starts with player X

Function Signature

def process_tic_tac_toe(commands):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output