PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amazon

Implement Multi-Player Tic-Tac-Toe

Last updated: Jul 28, 2026

Quick Overview

Implement multi-player Tic-Tac-Toe on a configurable board with strict turn order, validated moves, and a fixed three-mark win condition. Define exact status behavior for invalid and terminal moves while covering longer runs, ties, large boards, replay, undo, and configurable extensions.

  • medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Implement Multi-Player Tic-Tac-Toe

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

# Implement Multi-Player Tic-Tac-Toe Implement a game class for an `N` by `N` board and `K` players. Each player has a distinct one-character printable mark. The constructor receives the marks in fixed turn order. ```text TicTacToe(n, player_marks) play(player, row, col) -> Status getStatus() -> Status ``` `player_marks` is a nonempty ordered list of distinct marks and its length is `K`. `player` is one of those marks. A `Status` is the JSON-safe object `{state, winner}`, where `state` is one of `INVALID`, `IN_PROGRESS`, `WIN`, or `TIE`; `winner` is the winning mark only when `state` is `WIN`, and is `null` otherwise. Players take turns in constructor order. `play` validates that the game is still active, it is that player's turn, `0 <= row < N` and `0 <= col < N`, and the cell is empty. A rejected move—including an out-of-bounds coordinate—returns `{state: INVALID, winner: null}` without changing the board, turn, or persistent game status. An accepted move returns the new persistent status. `getStatus()` returns only that persistent status, so it never returns `INVALID`. A player wins immediately after forming three consecutive marks horizontally, vertically, or along either diagonal. A run longer than three also wins. If the board becomes full with no winner, the result is `TIE`. ## Constraints - `3 <= N <= 200` - `2 <= K <= 16` - At most `N * N` accepted moves. - Aim to inspect only lines through the latest move. ## Example For `TicTacToe(3, [X, O])`, plays `X(0,0)`, `O(1,0)`, `X(0,1)`, `O(1,1)`, `X(0,2)` end with `{state: WIN, winner: X}`. ## Clarifications The winning length is fixed at three even when `N` is larger. Once a terminal status is reached, all later plays are invalid and `getStatus` remains terminal. ## Hints Only four directions through the newest mark need to be checked, expanding in both directions. ## Extensions - Reduce space when wins require an entire row, column, or diagonal. - Support undo and replay. - Generalize to a configurable winning length.

Quick Answer: Implement multi-player Tic-Tac-Toe on a configurable board with strict turn order, validated moves, and a fixed three-mark win condition. Define exact status behavior for invalid and terminal moves while covering longer runs, ties, large boards, replay, undo, and configurable extensions.

Related Interview Questions

  • Schedule Priority Jobs with Cooldowns - Amazon (medium)
  • Find Paths Across a Weighted Binary Grid - Amazon (medium)
  • Compute Edit Distance - Amazon (medium)
  • Minimize Replacements So Equal Product Values Are Contiguous - Amazon (hard)
|Home/Coding & Algorithms/Amazon

Implement Multi-Player Tic-Tac-Toe

Amazon logo
Amazon
Jul 17, 2026, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
0
0

Implement Multi-Player Tic-Tac-Toe

Implement a game class for an N by N board and K players. Each player has a distinct one-character printable mark. The constructor receives the marks in fixed turn order.

TicTacToe(n, player_marks)
play(player, row, col) -> Status
getStatus() -> Status

player_marks is a nonempty ordered list of distinct marks and its length is K. player is one of those marks. A Status is the JSON-safe object {state, winner}, where state is one of INVALID, IN_PROGRESS, WIN, or TIE; winner is the winning mark only when state is WIN, and is null otherwise.

Players take turns in constructor order. play validates that the game is still active, it is that player's turn, 0 <= row < N and 0 <= col < N, and the cell is empty. A rejected move—including an out-of-bounds coordinate—returns {state: INVALID, winner: null} without changing the board, turn, or persistent game status. An accepted move returns the new persistent status. getStatus() returns only that persistent status, so it never returns INVALID.

A player wins immediately after forming three consecutive marks horizontally, vertically, or along either diagonal. A run longer than three also wins. If the board becomes full with no winner, the result is TIE.

Constraints

  • 3 <= N <= 200
  • 2 <= K <= 16
  • At most N * N accepted moves.
  • Aim to inspect only lines through the latest move.

Example

For TicTacToe(3, [X, O]), plays X(0,0), O(1,0), X(0,1), O(1,1), X(0,2) end with {state: WIN, winner: X}.

Clarifications

The winning length is fixed at three even when N is larger. Once a terminal status is reached, all later plays are invalid and getStatus remains terminal.

Hints

Only four directions through the newest mark need to be checked, expanding in both directions.

Extensions

  • Reduce space when wins require an entire row, column, or diagonal.
  • Support undo and replay.
  • Generalize to a configurable winning length.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

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

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding 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.