FastPrepUltimate Tic-Tac-Toe Move Simulator

Ultimate Tic-Tac-Toe Move Simulator

Hebbia logoHebbia● HardFULLTIMEPHONE SCREEN
Learn

Problem statement

Simulate Ultimate Tic-Tac-Toe from attempted moves. The game has a 3 × 3 grid of small 3 × 3 boards. Each move is boardRow,boardCol,cellRow,cellCol,player. Apply valid moves only and do not enforce alternating turns.

  • The previous valid move's cell coordinates force the next move into the corresponding small board.
  • If that forced board is full or captured, the next move may use any playable board.
  • A captured board is closed. Three captured boards in a row, column, or diagonal win the overall game.
  • Reject malformed moves, invalid coordinates or players, occupied cells, wrong forced boards, closed boards, and moves after an overall win.

Return: a validity bit string, the overall winner or None, the next forced board as r,c, * when any board is allowed, or None after a win, followed by the nine rows of the 9 × 9 display.

Function

simulateUltimateTicTacToe(moves: String[]) → String[]

Examples

Example 1

moves = []return = ["","None","*",".........",".........",".........",".........",".........",".........",".........",".........","........."]

An empty game has no winner, no forced board, and a blank display.

Example 2

moves = ["0,0,1,2,X"]return = ["1","None","1,2",".........","..X......",".........",".........",".........",".........",".........",".........","........."]

The cell coordinates force the next move to small board 1,2.

Example 3

moves = ["0,0,1,1,X","0,0,0,0,O","1,1,0,0,O"]return = ["101","None","0,0",".........",".X.......",".........","...O.....",".........",".........",".........",".........","........."]

The second move ignores the forced board and is rejected; the third is valid.

Constraints

  • 0 <= moves.length <= 100000
  • There are exactly nine 3 × 3 small boards.
  • Valid players are X and O.

More Hebbia problems

See Hebbia hiring insights
public String[] simulateUltimateTicTacToe(String[] moves) {
  // Write your code here.
}
moves[]
expected["", "None", "*", ".........", ".........", ".........", ".........", ".........", ".........", ".........", ".........", "........."]
Checking account…