← Databricks Interview Insights

Databricks·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Databricks coding interview with a grid pathfinding problem. Pretty standard BFS territory but the setup with the custom cell types threw me off for a second.

Questions Asked (1)

Q1

Given a 2D grid where cells are marked as start, destination, open road, or obstacle, 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 a graph and use BFS to find the shortest path, since all moves have equal cost. Start from the start cell, explore neighbors in four directions, and track visited cells to avoid cycles. Return the distance when reaching the destination, or -1 if the queue is exhausted.

Pro tip: Mention that BFS is optimal for unweighted grids, but if the grid is huge, consider bidirectional BFS or A* with Manhattan distance to reduce search space. Also, clarify edge cases like start equals destination or no path exists.

1. Clarify problem and constraints

Ask about grid size, movement rules, and whether diagonal moves are allowed. Confirm that start and destination are distinct and that obstacles block movement.

2. Choose BFS as the algorithm

Explain that BFS guarantees the shortest path in an unweighted graph. Use a queue to explore level by level, and a visited set or 2D array to avoid revisiting cells.

3. Implement BFS with direction vectors

Define four direction offsets (up, down, left, right). For each cell, check bounds and obstacles, then enqueue valid neighbors with distance incremented.

4. Handle termination and edge cases

Return distance when destination is dequeued. If queue empties, return -1. Handle start equals destination by returning 0 immediately.

5. Analyze complexity and optimizations

State time and space complexity as O(R*C). Discuss potential optimizations like bidirectional BFS or A* if the grid is very large.

Key Points to Mention

  • BFS is optimal for unweighted graphs, ensuring shortest path.
  • Use a queue for level-order traversal and a visited set to prevent cycles.
  • Check boundaries and obstacles before enqueuing neighbors.
  • Time and space complexity are O(R*C) for an R x C grid.
  • Edge cases: start equals destination, no path exists, empty grid.
  • Possible optimizations: bidirectional BFS, A* with Manhattan distance.

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