Detect Winners in Nested Tic-Tac-Toe
Company: Hebbiaai
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
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
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
- There are only 8 possible winning lines: 3 rows, 3 columns, and 2 diagonals.
- 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
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
- Write one helper that returns the winner of any 3 x 3 grid: 'X', 'O', or '.'.
- Build the 3 x 3 meta-board from the 9 small boards, then run the same helper on that meta-board.