← Back to challenges

O's and X's

PythonHardgamesarrays

Instructions

Given a list containing three strings, representing the rows of an O's and X's board from top to bottom, return the row and column position of the winning move for X's. Return False if the game cannot be won.

Examples

x_and_o(board = [" | | ", " |X| ", "X| | "]) ➞  [1, 3]

# Board becomes:
#    |   |
#    |X |
# X |   |

x_and_o(board = ["X|X|O", "O|X| ", "X|O| "]) ➞ [3, 3]

# Board becomes:
# X|X|O
# O|X|
# X|O|

Notes

There is no 0 index for the row or column.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.