← Back to challenges

Tic-Tac-Toe

PythonHardarraysgamesvalidation

Instructions

Create a function that takes a Tic-tac-toe board and returns "X" if the X's are placed in a way that there are three X's in a row or returns "O" if there is three O's in a row.

Examples

who_won([
  ["O", "X", "O"],
  ["X", "X", "O"],
  ["O", "X", "X"]
]) ➞ "X"

who_won([
  ["O", "O", "X"],
  ["X", "O", "X"],
  ["O", "X", "O"]
]) ➞ "O"

Notes

  • There are no Ties.
  • All places on the board will have either "X" or "O".
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.