Ultimate Tic-Tac-Toe Move Simulator
Updated
Problem statement
You are given a list of attempted moves in Ultimate Tic-Tac-Toe. Simulate the game and report the result.
The big board is a 3 × 3 grid of small boards. Each small board is a 3 × 3 grid of cells. Each move is a string boardRow,boardCol,cellRow,cellCol,player. The first two values pick the small board, the next two pick the cell inside it, and the last one is the player.
Apply only the valid moves and skip the rest. Players do not have to take turns, so the same player may move twice in a row.
- The cell used by the previous valid move picks the small board for the next move. For example, a move in the top-right cell of a small board sends the next move to the top-right small board.
- If that forced board is full or captured, the next move may go on any playable board.
- A captured board is closed. Three captured boards in a row, column, or diagonal win the whole game.
- Reject a move that is badly formed or uses an invalid coordinate or player. Also reject a move on a taken cell, on the wrong forced board, or on a closed board. Once the whole game is won, reject every later move.
Return an array of strings in this order:
- a validity bit string, with one bit for each attempted move,
- the overall winner, or
Noneif nobody has won, - the forced board for the next move as
r,c. Use*when any board is allowed, andNoneafter a win, - the nine rows of the 9 × 9 display.
Function
simulateUltimateTicTacToe(moves: String[]) → String[]Examples
Example 1
moves = []return = ["","None","*",".........",".........",".........",".........",".........",".........",".........",".........","........."]With no moves, the validity string is empty and nobody has won. Any board may be played next, so the forced board is *. The display is blank.
Example 2
moves = ["0,0,1,2,X"]return = ["1","None","1,2",".........","..X......",".........",".........",".........",".........",".........",".........","........."]The move is valid. X plays in the top-left small board. Its cell position inside that board forces 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 first move is valid. X plays the middle cell of the top-left board, so the next move must go to the middle board. The second move tries the top-left board instead, so it is rejected. The third move plays O in the middle board, so it is valid. It uses the top-left cell, so the next move goes to the top-left board. The validity string marks the first and third moves as valid.
Constraints
0 <= moves.length <= 100000- There are exactly nine 3 × 3 small boards.
- Valid players are
XandO.
More Hebbia interview questions
Similar questions at other companies
- Cats, Rabbits, and Snails Board GameAsana · ONSITE INTERVIEW
- Checkpointed Dynamic SequenceOpenAI · PHONE SCREENOpenAI interview questions
- Zigzag Board Adjacent SwapsUber · PHONE SCREENUber interview questions
- Chatter Message WindowReddit · PHONE SCREENReddit interview questions
- Scaled Dot-Product AttentionAmazon · PHONE SCREEN
- Versioned Recipe Shopping CartDecagon · PHONE SCREENDecagon interview questions
- Lazy Filter over a GeneratorSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
- Array-Backed Set Without Library CollectionsOde with Anthropic · PHONE SCREEN
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN