AO
Back

Count Every Possible Tic-Tac-Toe Game

Also reported as Tic Tac Toe

Phone ScreenPhone ScreenLast reported October 2026Medium Frequency

Problem Overview

The round: a Decagon coding question in five reports from April to October 2026: three phone screens (one for an AI engineer role) and two onsite coding rounds. The phone screens ask for the 3x3 count. One onsite asked for the same count on a 4x4 board with three in a row; another onsite candidate solved it by brute force and then added memoisation. Two graded parts.

Part 1 — every game on the 3x3 board

def count_games() -> int:
  • Two players take turns on an empty 3x3 board. X always moves first.
  • A game is the whole sequence of moves from the empty board to the end. It ends as soon as one player has three in a row (a row, a column or a diagonal), or when the board is full (a draw).
  • Different move orders count as different games, even when the final board is the same.
  • Return the number of different games. The reported answer is 255168.
  • Reported follow-up (discussion, not graded): before coding, estimate the order of magnitude. Filling the board in every order gives 9! = 362880, an upper bound, since many games end early.

Part 2 — a bigger board, k in a row

def count_games_board(rows: int, cols: int, k: int) -> int:
  • The same count on an empty rows x cols board where k in a row wins, along a row, a column or either diagonal. The game still ends at the first win or a full board.
  • The reported variant is a 4x4 board with three in a row; the report says only "all possible games", by recursion and backtracking. The other rules here are our assumptions, carried over from the 3x3 statement: X moves first, the game ends at the first win, different move orders are different games, and any three in a row wins, the short diagonals of length 3 included. Confirm each with the interviewer.
  • Under those rules the 4x4 count is 1281016086768 (about 1.3 trillion games, our computation), so walking the games one by one cannot finish; memoising on the position can (about 3.5 million positions, our count).
  • The 4x4 board is too big for this page, so the tests check smaller boards and grade only the counts. This page cannot time your code, so the memoisation one candidate added after brute force is not graded here; say it out loud.

Notes: the 3x3 statement, its answer, the 9! estimate, the 4x4 three-in-a-row variant and the memoisation step are reported. The function names, the general rows, cols, k signature, the 4x4 rules beyond the board size and three in a row, the 4x4 answer (we computed it; no report gives one) and all the Part 2 test boards are ours.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 3
Trade-off discussion

Before coding, estimate the order of magnitude of the answer.

Probes for: at the start; 9! = 362880 is an upper bound

Add memoisation to the brute force.

Probes for: after the backtracking works; one onsite candidate added it, and the report does not say whether the interviewer asked

Count all possible games on a 4x4 board where three in a row wins.

Probes for: an onsite variant of the question

What Reports Emphasize

Common mistakes: Placing marks after a win, which counts games that never happened.; Counting final boards instead of move sequences.; Running plain backtracking on the 4x4 variant, which has about 1.3 trillion games (our count).

What candidates did: One estimated the size first with 9! as an upper bound, then wrote the standard backtracking. One wrote brute force and then added memoisation. Two who were rejected say they got stuck debugging or were slow to produce the backtracking, so practise writing it cleanly and quickly.

Practice

Write your own against 5 test cases, or read the worked solution — approach, complexity, and code that runs.
Did this match your interview?

If you have had this round, tell us how close this page was. It is how we keep the pages accurate.

Prepping for Decagon with friends?

Send them this page. It is free to read, no account needed.

More Decagon Questions

Free preview

Every question in the Decagon catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 8 Decagon questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Decagon · Phone Screen · Reported 5× across candidate reports
Is this helpful?