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.

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.

Hints

  1. Choose a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.

Loading coding console...