PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Decagon

Enumerate 4x4 Tic-Tac-Toe Games

Last updated: May 27, 2026

Quick Overview

This question evaluates recursion, backtracking, combinatorial reasoning, game-tree enumeration, board state representation, and efficient win-detection in a turn-based game.

  • medium
  • Decagon
  • Coding & Algorithms
  • Software Engineer

Enumerate 4x4 Tic-Tac-Toe Games

Company: Decagon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given an empty 4x4 board. Two players, `X` and `O`, alternate turns, with `X` moving first. A player wins as soon as they create **three consecutive marks** in a row, column, or diagonal. Once a player wins, the game stops immediately. Write a program that uses recursion and backtracking to enumerate all valid game sequences from the empty board to a terminal state. A terminal state is either: - a win for `X`, - a win for `O`, or - a full board with no winner. You may return either: 1. the total number of valid terminal game sequences, or 2. all terminal boards / move sequences themselves. Be prepared to explain: - how you represent the board, - how you detect a win efficiently, - how recursion explores the game tree, - how backtracking restores state after each move, and - what the time complexity looks like in the worst case.

Quick Answer: This question evaluates recursion, backtracking, combinatorial reasoning, game-tree enumeration, board state representation, and efficient win-detection in a turn-based game.

Related Interview Questions

  • Implement a Recipe Cart - Decagon (medium)
  • Implement a CSAT Sliding Window Tracker - Decagon (easy)
  • Design rolling-window conversation score tracker - Decagon (easy)
  • Compute exclusive CPU time from nested logs - Decagon (medium)
  • Design a Tic-Tac-Toe Engine - Decagon (medium)
Decagon logo
Decagon
Mar 9, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
18
0

You are given an empty 4x4 board. Two players, X and O, alternate turns, with X moving first. A player wins as soon as they create three consecutive marks in a row, column, or diagonal. Once a player wins, the game stops immediately.

Write a program that uses recursion and backtracking to enumerate all valid game sequences from the empty board to a terminal state. A terminal state is either:

  • a win for X ,
  • a win for O , or
  • a full board with no winner.

You may return either:

  1. the total number of valid terminal game sequences, or
  2. all terminal boards / move sequences themselves.

Be prepared to explain:

  • how you represent the board,
  • how you detect a win efficiently,
  • how recursion explores the game tree,
  • how backtracking restores state after each move, and
  • what the time complexity looks like in the worst case.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Decagon•More Software Engineer•Decagon Software Engineer•Decagon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.