Compute nearest dashmart distances for queries
Company: DoorDash
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's understanding of graph traversal and shortest-path computation on grids, spatial reasoning about obstacles and sources, and the ability to analyze algorithmic scalability and complexity when answering many queries.
Constraints
- Movement is 4-directional
- Queries are answered in input order
Examples
Input: ([[2147483647, -1, 0, 2147483647], [2147483647, 2147483647, 2147483647, -1], [2147483647, -1, 2147483647, -1], [0, -1, 2147483647, 2147483647]], [[0, 0], [1, 1], [3, 3]])
Expected Output: [3, 2, 4]
Input: ([[-1, 2147483647], [2147483647, 2147483647]], [[0, 1], [1, 1]])
Expected Output: [-1, -1]
Input: ([[0]], [[0, 0], [1, 1]])
Expected Output: [0, -1]
Input: ([[2147483647, 2147483647]], [])
Expected Output: []
Hints
- Run one BFS from all dashmarts at once.
- Do not run a BFS per query when k is large.