← Machine Coding

Tic Tac Toe III

hard
Asked at
Apple
Microsoft
OpenAI
Apple, Microsoft, OpenAI

Problem statement

Tic Tac Toe III is the complete minimax AI implementation. Instead of a two-player game, the player faces a computer opponent that plays perfectly — it never loses. This tests your ability to implement the minimax algorithm in a React component and integrate it with the game state from previous parts.

Build on the Tic Tac Toe game engine to add a CPU player that uses minimax to find the optimal move. After the human plays, the CPU immediately calculates and plays its best response. The CPU should be unbeatable — the best outcome a human can achieve is a draw.

The algorithmic challenge is the minimax function: recursively evaluate all possible future game states, assign scores (+10 for CPU win, -10 for human win, 0 for draw), and pick the move with the highest score. Alpha-beta pruning is bonus credit.

Requirements & constraints

  • →CPU uses minimax to play optimally — never loses
  • →CPU plays automatically after human move
  • →Game correctly detects win, draw, and ongoing states
  • →Visual indicator shows CPU is thinking (even if instant)
  • →Human is always X (first), CPU is always O
  • →Restart button resets the game

How to approach Tic Tac Toe III

The strategy an interviewer expects you to reach for.

Why This Question Exists Tic Tac Toe III — the minimax AI — is one of the classic algorithm questions adapted for a UI context. It tests whether you can implement a recursive search algorithm, correctly model the game as a tree of states, and integrate the AI into React's state model cleanly. Candidates who know the algorithm but can't wire it to React's event loop fail this question.

Premium

The full solution is part of HelloFrontend Pro

The question above is free to read in full. Upgrade to unlock the interactive workspace and the senior-level walkthrough that go with it.

  • Live React sandbox pre-wired for this component
  • Time-boxed checkpoints that mirror a real 45-minute round
  • Interviewer scoring criteria and a full reference implementation
Unlock the full solution →

Already a member? Log in to open the workspace.

More Machine Coding questions

View all Machine Coding →
Machine CodingMedium

React Tic-Tac-Toe Engine

Machine CodingMedium

Performant Image Slider

Machine CodingMedium

API Search and Render Image

Machine CodingEasy

Accessible React Tabs

Machine CodingMedium

Recursive File Explorer

Machine CodingEasy

Stopwatch

Explore related prep hubs

  • All machine coding
  • Frontend machine coding guide
  • React machine coding questions
  • UI coding interview questions
  • React UI interview questions
  • Apple interview
  • Microsoft interview
  • OpenAI interview