← Databricks Interview Insights

Databricks·Software Engineer·Onsite - Coding / Algorithms·Senior

SeniorPrefer not to say
Jun 2026

Summary

Databricks software engineer interview with a coding round focused on game engine design. The problem was deceptively layered once they started asking about extensions and edge cases.

Questions Asked (3)

Q1

Design a Tic-Tac-Toe engine for an n x n board. Implement a move(row, col, player) function that returns whether the move is invalid, results in no winner yet, or declares a winner. Aim for O(1) time per move and O(n) space.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I got the basic win-check logic down pretty fast using row/col/diagonal counters per player, which is the standard trick.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Maintain row, column, and diagonal counters for each player to track progress toward a win, updating them in O(1) per move. On each move, validate the coordinates and cell emptiness, then increment the relevant counters and check if any reaches n. This achieves O(1) time and O(n) space.

Pro tip: Clarify upfront that the board state is stored separately (O(n^2) space) and that the O(n) space refers only to the auxiliary counters; this shows you understand the distinction and avoids confusion.

1. Clarify requirements and constraints

Confirm the board size n, player representation (e.g., 1 and 2), and that moves are 0-indexed. Discuss the space complexity: O(n) auxiliary space for counters, while the board itself takes O(n^2) if stored.

2. Design data structures

Use arrays of size n for row and column counts per player, and two scalars for the main diagonal and anti-diagonal counts per player. Also maintain the board (e.g., 2D array) to check cell occupancy.

3. Implement move validation and updates

Check if row/col are within bounds and the cell is empty; if not, return invalid. Otherwise, place the player's mark, increment the corresponding row, column, and diagonal counters (if applicable).

4. Check for win condition

After updating counters, check if any of the incremented counters equals n. If so, return that the player has won; otherwise, return no winner yet.

5. Analyze complexity and edge cases

Explain that each move is O(1) time and the auxiliary space is O(n). Discuss edge cases like n=1, invalid moves, and moves after a win.

Key Points to Mention

  • O(1) time per move achieved by incremental counter updates instead of scanning rows/columns/diagonals.
  • O(n) auxiliary space: two arrays of size n for rows and columns, plus four scalars for diagonals (per player).
  • Validation: check bounds and that the cell is empty before updating.
  • Win detection: a player wins if any row, column, or diagonal counter reaches n.
  • Board storage: if the board is stored, it requires O(n^2) space, but the algorithm's auxiliary space is O(n).
  • Edge cases: n=1, invalid moves, moves after game over, and handling multiple winners (though not possible in standard Tic-Tac-Toe).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Extend the Tic-Tac-Toe API to support a reset() method and an optional undo() operation.

System DesignAPI & IntegrationsTechnical Trade-offs
Author's notes

undo() is where things got interesting.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the existing API contract and state model, then design reset() as a straightforward state reinitialization and undo() as a command-pattern or history-stack-based operation. Discuss trade-offs around memory, performance, and API semantics, and outline how you would test and document both methods.

Pro tip: Treat undo() as a reversible command with a bounded history to avoid unbounded memory growth, and explicitly define edge cases like undoing before any move or after a reset. This shows you think about production concerns, not just happy paths.

1. Clarify requirements and existing design

Ask about the current API shape, state representation, and whether undo should be single-level or multi-level. Confirm constraints like thread safety, persistence, and backward compatibility.

2. Design reset()

Define reset() to clear the board, reset turn and game status, and optionally clear undo history. Discuss whether it should return the new state or void, and how it interacts with in-flight games.

3. Design undo() with a history mechanism

Propose storing moves as commands or snapshots in a stack, with a configurable max depth. Explain how to reverse a move (e.g., pop and restore previous state) and handle undo after reset or when history is empty.

4. Analyze trade-offs and edge cases

Compare command pattern vs. full state snapshots in terms of memory and complexity. Cover concurrency, idempotency, error signaling (exceptions vs. result types), and how undo affects game-over states.

5. Outline testing and API documentation

Describe unit tests for reset/undo sequences, boundary conditions, and concurrency. Mention updating API docs and versioning if the change is breaking.

Key Points to Mention

  • Command pattern or memento pattern for undo, with a bounded history stack to control memory.
  • Reset semantics: full state reinitialization vs. soft reset, and whether undo history is cleared.
  • Thread safety and concurrency considerations if the API is used in a multi-threaded environment.
  • Error handling for invalid undo (empty history) and undo after game completion or reset.
  • Backward compatibility and API versioning when extending the interface.
  • Testing strategy including unit tests for state transitions and edge cases.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Write comprehensive tests for the Tic-Tac-Toe engine covering edge cases like repeated moves on the same cell, out-of-bounds inputs, early wins before the board fills, and a completely filled board with no winner.

Algorithms & Data StructuresSystem Design
Author's notes

Honestly the part I was least prepared for.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the engine's API and rules (board size, win conditions, move validation), then structure tests around the game lifecycle: initialization, valid moves, invalid moves, win detection, draw detection, and edge cases. Use a table-driven approach to cover many scenarios efficiently and assert both state changes and error handling.

Pro tip: Mention that you'd test the engine as a black box through its public API, and that you'd use property-based testing to generate random move sequences to uncover unexpected edge cases.

1. Clarify requirements and API

Ask about the engine's interface, board representation, win conditions, and error handling. Confirm assumptions before writing tests.

2. Identify test categories

List categories: initialization, valid moves, invalid moves (repeated cell, out-of-bounds), win detection (rows, columns, diagonals), draw detection, and game state after game over.

3. Design test cases for each category

For each category, enumerate specific scenarios including edge cases like early win, full board draw, and invalid inputs. Use equivalence partitioning and boundary value analysis.

4. Implement tests with clear assertions

Write tests that assert both the expected outcome (e.g., exception, error code) and the resulting board state. Use parameterized tests to reduce duplication.

5. Review coverage and add property-based tests

Ensure all branches are covered. Consider property-based tests to generate random valid/invalid sequences and verify invariants (e.g., no two moves on same cell).

Key Points to Mention

  • Test invalid moves: repeated cell, out-of-bounds coordinates, moves after game over.
  • Test win detection for all rows, columns, and both diagonals, including early wins before board is full.
  • Test draw detection when board is full and no winner.
  • Use parameterized/table-driven tests to cover many cases efficiently.
  • Assert both the error/exception and that the board state remains unchanged after invalid moves.
  • Consider property-based testing to generate random move sequences and verify invariants.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.