FastPrepTic-Tac-Toe Winner on a Huge Board
Problems/Tic-Tac-Toe Winner on a Huge Board

Tic-Tac-Toe Winner on a Huge Board

Zillow logoZillow● MediumFULLTIMEINTERNPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Asked at Zillow from 2014 to 2016, in three reports. A software development manager candidate had it in an in-person process, a screen with the hiring manager and then a full interview loop; the report lists the question without saying which of the two. A software development engineer candidate had it in on-site interviews in Seattle. A software engineer intern candidate had a take-home task and then two phone interviews, the second one coding in an online compiler; the report does not tie this question to any one of these three steps.

Each report asks about tic-tac-toe on a board far too big to store cell by cell: one speaks of a huge grid, one of a board with no edges, and one gives a 2^31 by 2^31 board. The tasks were to check such a grid for a winning line, to build the game and decide when a player has won, and to pick a way of storing the board that still lets the program find the winner.

The reports do not say how many marks in a row win, how the board or the moves are passed in, what the answer looks like, or how long a game is. Here the function gets the moves in the order they were played, as [row, col] pairs of integers, and the integer k, the number of marks in a row that wins, and returns "X", "O" or "Pending" as a string. The board is 2^31 by 2^31, the size one report gives, with rows and columns numbered from 0; the same size stands in for the board with no edges, and the huge grid is given as its list of moves rather than cell by cell. X moves first and the players take turns. A line runs along a row, a column or either diagonal, and k or more marks in a row win, with k between 3 and 5,000. A game has 1 to 5,000 moves on different cells and stops at the first win, so no move comes after a winning move and the board never fills up, which leaves no draw.

Our version is about 75% the same as the reported question.

Two players, X and O, play tic-tac-toe on a square board with 2^31 rows and 2^31 columns, numbered from 0 to 2^31 - 1. The board starts empty.

You are given the moves in the order they were played: moves[i] = [row, col] is the cell marked on move i. X moves first and the players take turns, so X makes the moves at even indexes and O makes the moves at odd indexes. A player wins as soon as k or more of their marks stand in a row with no gap: along a row, along a column, or along either diagonal.

Return "X" or "O" for the player who won. If nobody has won after the last move, return "Pending". A game this short can never fill the board, so there is no draw.

Function

ticTacToeWinner(moves: int[][], k: int) → String

Examples

Example 1

moves = [[0,0],[5,5],[1,1],[5,6],[2,2]]k = 3return = "X"

X makes the moves at indexes 0, 2 and 4: [0,0], [1,1] and [2,2]. After index 4 these three cells form a diagonal line of 3, so X wins.

Example 2

moves = [[2147483647,2147483647],[0,2147483645],[7,7],[0,2147483646],[100,3],[0,2147483647]]k = 3return = "O"

O marks [0,2147483645], [0,2147483646] and [0,2147483647]: three cells side by side in row 0, ending at the last column. The last move, at index 5, completes the line, so O wins. One step to the right of column 2147483647 is off the board.

Example 3

moves = [[10,10],[0,0],[10,11],[0,1],[10,12],[1,0]]k = 4return = "Pending"

X has 3 marks in a row, [10,10], [10,11] and [10,12], but k = 4. O has no line of 4 either, so nobody has won yet.

Example 4

moves = [[1,3],[0,0],[2,3],[9,9],[4,3],[0,9],[3,3]]k = 4return = "X"

Before the last move, X holds [1,3], [2,3] and [4,3] in column 3, with a gap at row 3. The last move fills [3,3]: counting up from it gives 2 more marks (rows 2 and 1) and counting down gives 1 more (row 4), so the column holds 4 in a row and X wins.

Constraints

  • 1 <= moves.length <= 5000
  • moves[i].length == 2
  • 0 <= moves[i][0], moves[i][1] <= 2147483647 (that is, 2^31 - 1)
  • 3 <= k <= 5000
  • All cells in moves are different.
  • The game stops as soon as a player wins, so no move comes after a winning move.

More Zillow Onsite Interview questions

  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
  • Spiral MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
  • First Subarray with the Largest SumOA · ONSITE INTERVIEW · Seen Aug 2021
  • Count Duplicate CharactersONSITE INTERVIEW · Seen Oct 2020
  • Decision Tree Classifier from ScratchONSITE INTERVIEW · Seen Nov 2019
  • Find Median from Data StreamPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2018
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2016
  • Most Frequent Three-Page SequencesPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2016
  • Maximum Path Sum in a GridONSITE INTERVIEW · Seen Apr 2016

Similar questions at other companies

  • Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Configurable Tic-Tac-Toe GameEliseAI · PHONE SCREEN
  • Game of Life on a Finite and an Infinite BoardCitadel · PHONE SCREENCitadel interview questions
  • BitFont Part 2 - Render a WordStripe · ONSITE INTERVIEWStripe interview questions
  • Layered Rectangle CanvasRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Cache Shared Image Pipeline PrefixesAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • First Completed Mingo LineEpic · OAEpic interview questions
  • Hidden ArtifactsIMC Trading · OAIMC Trading interview questions
  • Sustained Overspeed AlertsFleetx · ONSITE INTERVIEW
  • LRU CacheAthenahealth · PHONE SCREEN
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public String ticTacToeWinner(int[][] moves, int k) {
        // Write your code here.
    }
}
Checking account…