#34 - Find Winner on a Tic Tac Toe Game

You are given a 3x3 Tic-Tac-Toe board as a list of lists, where each inner list represents a row in the board. Each cell in the board contains either "X", "O", or an empty space " ".

Your task is to implement a function to determine the winner of the game.

  1. The winner can be "X" if player X has filled either a row, a column, or a diagonal with their symbol.

  2. Similarly, the winner can be "O" if player O has filled either a row, a column, or a diagonal with their symbol.

  3. If there is no winner yet but board is incomplete, the game is considered to be ongoing.

  4. If there is no winner yet but board is complete, match is found to be Draw.

Example 1

Input

board =
[
    ["X", "O", "X"],
    ["O", "X", "O"],
    ["O", "X", "X"]
]

Output

Winner = "X"

Example 2

Input

board =
[
    ["X", "X", "O"],
    ["O", "O", "X"],
    ["O", "X", "X"]
]

Output

Winner = "O" 

Example 3

Input

board =
[
    ["X", " ", "O"],
    [" ", " ", "X"],
    ["O", "X", "X"]
]

Output

Ongoing Match

Example 4

Input

board =
[
    ["X", "X", "O"],
    ["O", "O", "X"],
    ["O", "X", "X"]
]

Output

Draw Match

Last updated