Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Tic Tac Toe Coding
00:00
5 left

Tic Tac Toe Coding

MediumPython

Problem

Chewy is prototyping a Tic Tac Toe feature for a customer-facing game experience. Given the board size and the moves played in order, determine whether player A wins, player B wins, the game ends in a draw, or play is still pending.

The board is an n x n grid. Players alternate turns, with A moving first. A player wins when all cells in any row, column, main diagonal, or anti-diagonal belong to that player. The input contains only valid moves, and no moves occur after the game has ended.

Formal Specification

Implement tic_tac_toe(n, moves), where n is an integer and moves is a list of coordinate pairs [row, column]. Return one of the strings "A", "B", "Draw", or "Pending".

Do not allocate an n x n board. Track only the information needed to determine whether the latest move completes a winning line.

Constraints

  • 3 <= n <= 1000
  • 0 <= len(moves) <= n * n
  • Each move is a valid pair [row, column]
  • 0 <= row, column < n
  • Moves alternate between players A and B
  • No move occurs after a winner is determined

Function Signature

def tic_tac_toe(n, moves):
Interviewer

Your question is Tic Tac Toe Coding. 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
Sign up free to run your codeLog inLn 2
Run your code to see test output here.