0 day streak
Anonymous · shared experience20 Feb 2025 · 10 views

Databricks: Pick the fastest single transport mode across a city grid, ties by cost

Interview question #Databricks Phone screen

Problem. A city is a 2D grid. One cell is the start S, one is the destination D, and cells marked X are roadblocks. Every other cell holds a number from 1 to 4, the transport mode that serves it. You also get two arrays:

  • time[i]: minutes per move with mode i
  • cost[i]: the fixed cost of choosing mode i

You move up, down, left or right. You choose one mode and keep it for the whole trip, and you cannot pass through roadblocks. Return the mode that reaches D fastest. If several modes tie on time, return the cheapest.

Example grid.

1 2 3 S 1 2 4
X 2 3 2 1 X 2
2 1 1 D 2 X 4

Notes. A natural approach is one BFS per mode, counting moves, then comparing moves times time[i]. The post gives no size limits and no expected output for the example. No follow-ups were asked. The candidate said the interviewer seemed satisfied with a correct solution, but the result was a rejection with no feedback.

0 comments

Comments 0

No comments yet. Ask the author something, or add what happened in your own round.