Problem 253951 · medium · Phase 02 Linear Data Structures

Tic-Tac-Toe Referee

2d-lists · game-state · lines

A tic-tac-toe board is a 3x3 grid of strings, each "X", "O" or "." (empty). Given board, return:

  • "X" or "O" if that player has three in a row (a full row, column or either diagonal),
  • "Draw" if nobody has won and there are no empty cells,
  • "Pending" otherwise.

At most one player will have a winning line.

Examples

Input:  board = [["X", "O", "."],
                 ["X", "O", "."],
                 ["X", ".", "O"]]
Output: "X"

Input:  board = [["X", "O", "X"],
                 ["X", "O", "O"],
                 ["O", "X", "X"]]
Output: "Draw"

Input:  board = [["X", ".", "."],
                 [".", "O", "."],
                 [".", ".", "."]]
Output: "Pending"

Constraints

  • board is always 3x3 and contains only "X", "O", "."

Goals

  • Enumerate all eight winning lines of a 3x3 board
  • Distinguish a finished game from one still in progress
Starting Python…