PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates board-evaluation and pattern-detection skills, modular decomposition for reusable logic, and the ability to reason about time and space complexity over hierarchical game states.

  • medium
  • Hebbiaai
  • Coding & Algorithms
  • Software Engineer

Detect Winners in Nested Tic-Tac-Toe

Company: Hebbiaai

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement functions for two related board-evaluation problems. **Part 1: Classic Tic-Tac-Toe** Given a 3 x 3 board represented by characters `'X'`, `'O'`, and `'.'` (empty), determine the current game result: - `'X'` if player X has three in a row, - `'O'` if player O has three in a row, - `'Draw'` if the board is full and nobody has won, - `'Pending'` otherwise. A win means three identical non-empty marks in any row, column, or diagonal. **Part 2: Nested Tic-Tac-Toe Follow-up** Now consider a 9 x 9 board formed by a 3 x 3 grid of smaller 3 x 3 tic-tac-toe boards. Each small board is evaluated independently. - If a player wins a small 3 x 3 board, that entire small board is considered conquered by that player. - The outer game is then treated as a 3 x 3 meta-board of conquered small boards. - A player wins the overall game if they conquer three small boards in a row, column, or diagonal on the outer board. Given the full 9 x 9 board state, determine whether there is an overall winner. You may assume the board contains only `'X'`, `'O'`, and `'.'`. Clarify your time and space complexity, and explain how you would structure the solution so the small-board logic can be reused for the outer board.

Quick Answer: This question evaluates board-evaluation and pattern-detection skills, modular decomposition for reusable logic, and the ability to reason about time and space complexity over hierarchical game states.

Part 1: Evaluate a Classic Tic-Tac-Toe Board

You are given a 3 x 3 tic-tac-toe board represented by 3 strings. Each character is 'X', 'O', or '.' for an empty cell. Determine the current result of the game. Return 'X' if player X has a winning row, column, or diagonal, return 'O' if player O has one, return 'Draw' if the board is full and nobody has won, and return 'Pending' otherwise. You do not need to validate move counts; only evaluate the board state.

Constraints

  • board.length == 3
  • Each board[i].length == 3
  • Each cell is one of 'X', 'O', or '.'
  • The test cases assume there is at most one winner

Examples

Input: ['XXX', 'O.O', '..O']

Expected Output: 'X'

Explanation: X has three in a row on the top row.

Input: ['OXX', 'XO.', '..O']

Expected Output: 'O'

Explanation: O wins on the main diagonal.

Input: ['XOX', 'XXO', 'OXO']

Expected Output: 'Draw'

Explanation: The board is full and neither player has a winning line.

Input: ['...', '...', '...']

Expected Output: 'Pending'

Explanation: Edge case: an empty board has no winner and still has moves remaining.

Hints

  1. There are only 8 possible winning lines: 3 rows, 3 columns, and 2 diagonals.
  2. Check for a winner first. Only if there is no winner should you decide between 'Draw' and 'Pending'.

Part 2: Detect the Winner in Nested Tic-Tac-Toe

You are given a 9 x 9 board representing a 3 x 3 grid of smaller tic-tac-toe boards. Each small 3 x 3 board is evaluated independently. If X wins a small board, that small board becomes 'X' on an outer 3 x 3 meta-board. If O wins a small board, it becomes 'O' on the meta-board. If a small board is drawn or still unfinished, it contributes '.' to the meta-board. The overall winner is the player who gets three conquered small boards in a row, column, or diagonal on the meta-board. Return 'X', 'O', or 'None'. Structure your solution so the same 3 x 3 winner-checking logic can be reused for both the small boards and the meta-board.

Constraints

  • board.length == 9
  • Each board[i].length == 9
  • Each cell is one of 'X', 'O', or '.'
  • For each 3 x 3 small board, the test cases assume there is at most one winner

Examples

Input: ['.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........']

Expected Output: 'None'

Explanation: Edge case: no small board has been conquered, so there is no overall winner.

Input: ['XXXXXXXXX', '.........', '.........', '.........', '.........', '.........', '.........', '.........', '.........']

Expected Output: 'X'

Explanation: X wins all three small boards in the top row, so X wins the meta-board.

Input: ['OOO......', '.........', '.........', '...OOO...', '.........', '.........', '......OOO', '.........', '.........']

Expected Output: 'O'

Explanation: O wins the top-left, center, and bottom-right small boards, forming a diagonal on the meta-board.

Input: ['XXX...OOO', '.........', '.........', '...XXX...', '.........', '.........', 'OOO......', '.........', '.........']

Expected Output: 'None'

Explanation: Several small boards are conquered, but neither player forms three in a row on the meta-board.

Hints

  1. Write one helper that returns the winner of any 3 x 3 grid: 'X', 'O', or '.'.
  2. Build the 3 x 3 meta-board from the 9 small boards, then run the same helper on that meta-board.
Last updated: Apr 26, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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.