← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Google SWE interview with a Tic-Tac-Toe engine problem that sounds straightforward but has enough edge cases to keep you busy for the whole session. The complexity discussion at the end was what they really cared about.

Questions Asked (1)

Q1

Design and implement a Tic-Tac-Toe game engine that supports k players on an n x n board, where a player wins by forming 3 consecutive marks in any direction. The implementation should handle invalid moves and return the correct game status after each move. Be prepared to discuss time and space complexity.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

I started with the classic 3x3 mental model and had to consciously reset when I realized n could be huge.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and edge cases (e.g., k players, n x n board, win condition of 3 consecutive marks, invalid moves). Then outline a class design with methods for move, status check, and win detection, focusing on efficient win checking by scanning only around the last move. Finally, analyze time and space complexity and discuss potential optimizations or trade-offs.

Pro tip: Demonstrate awareness of real-world constraints: mention that checking only the last move's row, column, and diagonals reduces win detection from O(n^2) to O(1) per move, and discuss how to handle invalid moves gracefully with exceptions or error returns.

1. Clarify Requirements and Edge Cases

Ask clarifying questions about k (number of players), n (board size), win condition (exactly 3 or at least 3?), and how invalid moves should be handled. Confirm that the game ends when a player wins or the board is full.

2. Design the Data Structures and Interface

Propose a class with an n x n board (e.g., 2D array or 1D array), a list of players, and methods like move(player, row, col) and getStatus(). Define how to track the current player and game state.

3. Implement Move Validation and Win Detection

For each move, validate that the cell is empty and the player is correct. After placing the mark, check for a win by scanning only the row, column, and two diagonals passing through the last move for 3 consecutive marks of that player.

4. Analyze Complexity and Discuss Trade-offs

Explain that move validation is O(1), win detection is O(1) (since only constant number of cells checked), and space is O(n^2). Discuss alternative approaches like precomputing counts or using bitboards for larger n.

5. Test with Examples and Edge Cases

Walk through a few moves, including invalid ones, and show how the status updates. Test edge cases like a win on the last move, a draw, and multiple players.

Key Points to Mention

  • Efficient win detection by checking only the last move's row, column, and diagonals.
  • Handling invalid moves: out-of-bounds, occupied cell, wrong player, or move after game over.
  • Time complexity: O(1) per move for win check, O(n^2) space for board.
  • Trade-offs: precomputing counts vs. on-the-fly checking; bitboards for performance.
  • Game status: ongoing, win (with winner), draw.
  • Scalability: how the solution changes if win condition is longer than 3 or board is very large.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.