FastPrepTic-Tac-Toe Game Over

Tic-Tac-Toe Game Over

ByteDance logoByteDance● EasyFULLTIMENEW GRADPHONE SCREEN
Learn

Problem statement

You are given an n × n tic-tac-toe board encoded as n strings. Cells contain 'X', 'O', or '.' for empty.

Return true if the game is over: either one player fills an entire row, column, main diagonal, or anti-diagonal, or the board is full and has no winner. Otherwise return false.

Function

gameOver(board: String[]) → boolean

Examples

Example 1

board = ["XXX","O.O","..O"]return = true

X fills the first row.

Example 2

board = ["XO","OX"]return = true

The board is full, so the game ended even without considering another move.

Constraints

  • 1 <= n <= 500.
  • Every row has length n and uses only X, O, and ..

More ByteDance problems

See ByteDance hiring insights
public boolean gameOver(String[] board) {
  // write your code here
}
board["XXX","O.O","..O"]
expectedtrue
Checking account…