Databricks: Pick the fastest single transport mode across a city grid, ties by cost
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 modeicost[i]: the fixed cost of choosing modei
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.
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.