Problem 177040 · medium · Phase 01 Prerequisites & Setup

Tic-Tac-Toe Winner

nested loops · strings · conditionals

board is a tic-tac-toe position given as three strings of three characters, each X, O or . (empty). Return "X" if X has three in a row (any row, column or diagonal), "O" if O does, and "" (empty string) if nobody has won yet. The board never contains two winners.

Examples

Input:  board = ["XOX", "OXO", "..X"]
Output: "X"

Input:  board = ["XOX", "XOO", "OXX"]
Output: ""

Input:  board = ["OOO", "XX.", "..."]
Output: "O"

Constraints

  • board always has exactly 3 rows of 3 characters.

Goals

  • Enumerate all winning lines of a 3x3 board systematically
  • Check whether three cells hold the same non-empty symbol
Starting Python…