PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Microsoft

Implement a Tic-Tac-Toe game class

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's competence in designing efficient stateful data structures and algorithmic optimization for an n×n game implementation, focusing on time-space trade-offs and robust API design.

  • medium
  • Microsoft
  • Coding & Algorithms
  • Software Engineer

Implement a Tic-Tac-Toe game class

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem Implement a class that supports playing an **n × n** Tic-Tac-Toe game. ### Requirements Create a class `TicTacToe(n)` with: - `move(row, col, player) -> int` - `row` and `col` are 0-indexed coordinates. - `player` is either `1` or `2`. - Each call places the player's mark at `(row, col)` (assume the move is always valid and the cell is empty). - Return: - `0` if there is no winner after this move, - `1` if player 1 wins after this move, - `2` if player 2 wins after this move. A player wins if they fill an entire **row**, **column**, **main diagonal**, or **anti-diagonal**. ### Constraints (typical interview assumptions) - `2 <= n <= 10^4` (so you should avoid O(n) scanning per move) - Many moves may be made; aim for **O(1)** time per `move` and **O(n)** space.

Quick Answer: This question evaluates a candidate's competence in designing efficient stateful data structures and algorithmic optimization for an n×n game implementation, focusing on time-space trade-offs and robust API design.

Related Interview Questions

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)
Microsoft logo
Microsoft
Oct 14, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
5
0

Problem

Implement a class that supports playing an n × n Tic-Tac-Toe game.

Requirements

Create a class TicTacToe(n) with:

  • move(row, col, player) -> int
    • row and col are 0-indexed coordinates.
    • player is either 1 or 2 .
    • Each call places the player's mark at (row, col) (assume the move is always valid and the cell is empty).
    • Return:
      • 0 if there is no winner after this move,
      • 1 if player 1 wins after this move,
      • 2 if player 2 wins after this move.

A player wins if they fill an entire row, column, main diagonal, or anti-diagonal.

Constraints (typical interview assumptions)

  • 2 <= n <= 10^4 (so you should avoid O(n) scanning per move)
  • Many moves may be made; aim for O(1) time per move and O(n) space.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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

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