Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Tic Tac Toe Winner


Interview Question

Implement an algorithm that determines if someone has won a game of tic-tac-toe


Algorithm

  • To determine if any of the two players have won the TicTacToe game or not, We need to know the following

  • Does any row, column or diagonal has scored the maximum?

  • Hence, we can aggregate the score for each row, column, diagonal in one dimension array.

For example, 3 * 3 board stateOfTheGame = [ row1, row2, row3, col1, col2, col3, diagonal1, diagonal2 ]


Solution


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *