Design Tic-Tac-Toe With K Players
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's ability to design and implement a game engine, manage board state and turn logic, validate moves, and apply efficient data structures and algorithms for win detection within the Coding & Algorithms domain.
Constraints
- 1 <= n <= 10^9
- 1 <= k <= 10^5
- 0 <= len(moves) <= 2 * 10^5
- Each move is a list of three integers: [player, row, col]
- Row and column in the input may be outside the board and should then be treated as an invalid move
- Your approach should be efficient for large n, so avoid scanning the whole board after every move
Examples
Input: (3, 2, [])
Expected Output: []
Explanation: No moves are made, so there are no statuses to report.
Input: (5, 2, [[1, 0, 0], [2, 1, 0], [1, 0, 1], [2, 1, 1], [1, 0, 2], [2, 2, 2]])
Expected Output: ['Continue', 'Continue', 'Continue', 'Continue', '1 won', 'Game Over']
Explanation: Player 1 forms three consecutive marks horizontally at (0,0), (0,1), and (0,2). Any later move returns 'Game Over'.
Hints
- Only the latest valid move can create a new 3-in-a-row, so you never need to rescan the entire board.
- For large boards, store only occupied cells in a hash map keyed by (row, col), then check the 4 line directions around the new move.