Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

TicTacToe Move Handling

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

Your question is TicTacToe Move Handling. 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

Scribd's mobile reading experience may need lightweight game-state logic for interactive content. Given a legal sequence of Tic-Tac-Toe moves, determine whether player A won, player B won, the game is a draw, or play is still pending.

Players alternate turns, with A moving first. The board has three rows and three columns. A player wins immediately after placing a mark in an entire row, column, or diagonal. The input sequence stops when the game ends or when all nine cells are filled.

Formal Specification

Implement tictactoe(moves), where moves is a list of coordinate pairs. The first pair belongs to A, the second to B, and so on. Return one of the strings "A", "B", "Draw", or "Pending".

Constraints

  • 0 <= len(moves) <= 9
  • Each move is a coordinate pair [row, column]
  • 0 <= row, column < 3
  • Moves are legal, alternate between A and B, and contain no repeated cell
  • The sequence stops immediately after a winning move

Function Signature

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