FastPrepDetect a Winner on a 3x3 Tic-Tac-Toe Board
Problems/Detect a Winner on a 3x3 Tic-Tac-Toe Board

Detect a Winner on a 3x3 Tic-Tac-Toe Board

Hebbia logoHebbia● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Hebbia onsite interview. A public interview question page gives the full rules for the 3x3 board, the assumption that the state is legal, the return values, and the onsite stage. Our version matches the reported question exactly.

Given a completed or partially completed 3 × 3 Tic-Tac-Toe board, return X if X occupies a complete row, column, or diagonal, return O if O does, and otherwise return None.

Each row is a string containing only X, O, and .. The board is reachable from legal alternating play, so it cannot contain simultaneous winners.

Function

ticTacToeWinner(board: String[]) → String

Examples

Example 1

board = ["XXX","O.O","..."]return = "X"
board
0120XXX1O.O2...

X fills the first row.

Example 2

board = ["XO.","XO.",".O."]return = "O"
board
0120XO.1XO.2.O.

O fills the middle column.

Example 3

board = ["XO.","OX.","..."]return = "None"
board
0120XO.1OX.2...

No row, column, or diagonal is complete.

Constraints

  • board.length == 3
  • board[i].length == 3
  • Every character is X, O, or ..
  • The board has no simultaneous winners.

More Hebbia interview questions

  • LRU Cache Snapshot PrinterONSITE INTERVIEW · Seen Feb 2026
  • Ultimate Tic-Tac-Toe Move SimulatorPHONE SCREEN · Seen May 2026
  • Most Relevant Text SpanPHONE SCREEN · Seen Apr 2025

Similar questions at other companies

  • Traverse Interior Matrix Cells in Row-Major OrderCitadel · ONSITE INTERVIEWCitadel interview questions
  • Spiral MatrixAthenahealth · ONSITE INTERVIEW
  • Spiral MatrixNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Incremental Hard Attention with a KV CacheOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Stochastic Gradient Descent with MomentumMeta · ONSITE INTERVIEWMeta interview questions
  • Cache Shared Image Pipeline PrefixesAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Minesweeper Board UpdateUber · ONSITE INTERVIEWUber interview questions
  • Cats, Rabbits, and Snails Board GameAsana · ONSITE INTERVIEW
  • Transformer Attention and SwiGLU Forward PassGoogle · ONSITE INTERVIEWGoogle interview questions
  • Diagonal Matrix IteratorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
See Hebbia hiring insights
Saved
class Solution {
    public String ticTacToeWinner(String[] board) {
      // Write your code here.
    }

}
Checking account…