← Databricks Interview Insights

Databricks·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Databricks coding screen, one algorithmic problem on grid traversal. Pretty standard stuff but the edge cases will get you if you're not careful.

Questions Asked (1)

Q1

Given a 2D grid with a start cell, a destination cell, open roads, and blocked cells, find the shortest path from start to destination moving only in four directions. Return -1 if no path exists.

Algorithms & Data Structures
Author's notes

Classic BFS setup.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the grid as an unweighted graph and use BFS from the start cell to find the shortest path to the destination, since BFS explores level by level and guarantees the minimum number of steps. Track visited cells to avoid cycles and return the distance when the destination is reached, or -1 if the queue is exhausted.

Pro tip: Clarify edge cases upfront—such as start equals destination, start or destination blocked, or empty grid—and mention that BFS is optimal for unweighted grids, while A* could be used if heuristics are available. This shows you think about correctness and performance trade-offs.

1. Clarify problem constraints and edge cases

Ask about grid size, whether diagonal moves are allowed, if start/destination can be blocked, and if the grid can be empty. Confirm that movement is only in four directions and that each step costs 1.

2. Choose BFS and explain why

State that BFS is ideal for unweighted shortest path because it explores all nodes at distance k before distance k+1, guaranteeing the first time you reach the destination is via a shortest path.

3. Outline BFS algorithm with queue and visited set

Initialize a queue with the start cell and a visited set (or distance matrix). While the queue is not empty, dequeue a cell, check if it's the destination, and enqueue all valid unvisited neighbors (within bounds, not blocked).

4. Handle termination and return value

If the destination is reached, return the current distance (or the distance stored for that cell). If the queue empties without reaching the destination, return -1.

5. Analyze complexity and potential optimizations

State that time and space complexity are O(R*C) where R and C are grid dimensions. Mention that A* with a heuristic (e.g., Manhattan distance) could be faster in practice but BFS is simpler and sufficient.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs
  • Use a queue for level-order traversal
  • Track visited cells to avoid infinite loops
  • Check boundaries and blocked cells before enqueuing neighbors
  • Return -1 if destination is unreachable
  • Time and space complexity O(R*C)

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