You are given a 2D grid representing a city map.
Each cell contains one of the following characters:
'O'— an open road (you can travel up, down, left, or right)'X'— a blocked road (cannot be passed through)'D'— a DashMart location
You are allowed to move in four directions:
up, down, left, right
You are given a list of query locations in:[row, col] format
For each query location, return the minimum distance to the nearest DashMart.
If the location is out of bounds or cannot reach any DashMart, return -1.
Example
City Map
0 1 2 3 4 5 6 7 8
0 ['X','O','O','D','O','O','X','O','X']
1 ['X','O','X','X','O','O','O','O','X']
2 ['O','O','O','D','X','X','O','X','O']
3 ['O','O','O','D','O','X','O','O','O']
4 ['O','O','O','O','O','X','O','O','X']
5 ['O','O','O','O','X','O','O','X','X']
Locations Input
[
[200, 200],
[1, 4],
[0, 3],
[5, 8],
[1, 8],
[5, 5]
]
Expected Output
[-1, 2, 0, -1, 6, 9]
Explanation Summary:
- (200,200) is out of grid →
-1 - (1,4) shortest path to nearest D → distance = 2
- (0,3) is directly on a D → 0
- (5,8) cannot reach any D →
-1 - (1,8) can reach → distance = 6
- (5,5) reaches → distance = 9
Function Signature
Complete the getClosestDashmartDistance function.
Parameters:
1. 2D_CHARACTER_ARRAY cityMap
2. 2D_INTEGER_ARRAY locations
Return:
INTEGER_ARRAY result
This DoorDash VO question evaluates a candidate’s ability to compute the shortest path from multiple points to the nearest DashMart in a 2D grid.
Key expectations from the interviewer:
✅ 1. Proper BFS reasoning
This is a classic shortest-path problem on a grid.
BFS guarantees minimal distance because all moves have equal cost.
Candidates should explain:
- BFS from each query → too slow
- Reverse BFS from all DashMarts → optimal
- Multi-source BFS improves performance drastically
- Handling out-of-bound or unreachable locations
✅ 2. Engineering constraints
The map can be large, and number of queries can be large, so the candidate must avoid repeated BFS per query.
✅ 3. Correct handling of obstacles
Cells containing 'X' must be respected as walls.
✅ 4. Edge cases
- Query out of bounds
- Query lands directly on
'D' - Completely enclosed areas
- No reachable DashMart → return
-1
This problem tests reasoning, optimization, BFS mastery, and ability to map theory to engineering constraints.
The VOprep team has long accompanied candidates through various major company OAs and VOs, including Doordash, Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for Tiktok or similar engineering-focused companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.