Tic-Tac-Toe with K Players
Asked at Google
Reported by the problem's creator, not verified
Tic-tac-toe on an n x n board played by k players. Players are numbered 0 to k - 1 and play in that order, starting with player 0 and returning to player 0 after player k - 1.
Examples
Example 1
Input: init =
[3,2], operations =[["move",[0,0]],["move",[0,0]],["move",[1,0]],["move",[1,1]],["move",[0,1]],["move",[2,2]],["move",[2,0]]]Output:
["In progress","Invalid","In progress","In progress","In progress","Player 0 wins","Invalid"]Explanation: Player 0 takes (0,0). Player 1 tries the same cell and gets
Invalid, so player 1 plays (1,0). Player 0 takes (1,1), player 1 takes (0,1), and player 0 takes (2,2), completing the main diagonal. Any later move isInvalid.Example 2
Input: init =
[3,2], operations =[["move",[0,0]],["move",[0,1]],["move",[0,2]],["move",[1,1]],["move",[1,0]],["move",[1,2]],["move",[2,1]],["move",[-1,0]],["move",[2,0]],["move",[2,2]],["move",[0,0]]]Output:
["In progress","In progress","In progress","In progress","In progress","In progress","In progress","Invalid","In progress","Draw","Invalid"]Explanation: Nine valid moves fill the board without three in a row, so the ninth returns
Draw. The earlier (-1,0) is off the board and returnsInvalidwithout using a turn, and the move after the end returnsInvalid.