Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Tic-Tac-Toe Logic Implementation
00:00
5 left

Tic-Tac-Toe Logic Implementation

MediumPython

Problem

Implement the game of Tic-Tac-Toe (X/O) with focus on logic.

Given an ordered list of moves, where X plays first and players alternate, process every move on a 3x3 board. Return Invalid for an out-of-range coordinate or an occupied cell. After processing all moves, return the player symbol associated with the final move if the board contains a winning line, Draw if the board is full without a winner, or In Progress otherwise.

Contract

moves is a list of [row, column] pairs. Return one of "X", "O", "Draw", "In Progress", or "Invalid".

Constraints

  • 0 <= len(moves) <= 9
  • Each move contains exactly two integer coordinates
  • Rows and columns must be in the range 0 through 2
  • X always makes the first move

Function Signature

def tic_tac_toe(moves):
Interviewer

Your question is Tic-Tac-Toe Logic Implementation. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.