PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

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.

Simulate n x n Tic-Tac-Toe moves and return winner status after each move.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: (3, [(0,0,1),(0,2,2),(1,1,1),(0,1,2),(2,2,1)])

Expected Output: [0, 0, 0, 0, 1]

Explanation: Player 1 wins diagonal.

Input: (2, [(0,1,2),(1,1,2)])

Expected Output: [0, 2]

Explanation: Player 2 wins column.

Input: (3, [])

Expected Output: []

Explanation: No moves.

Hints

  1. Choose a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.
Last updated: Jun 27, 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.

Related Coding 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)