FastPrepClosest DashMart
Problems/Closest DashMart

Closest DashMart

DoorDash logoDoorDash● MediumFULLTIMEOAPHONE SCREEN

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source image marks X cells as blocked but includes queries that begin on them. The judged contract makes the source's implied one-step departure rule explicit and otherwise matches the visible source at about 98%.

A DashMart is a warehouse that houses items found in convenience stores, grocery stores, and restaurants. A city is represented as a rectangular grid containing open roads, blocked roads, and DashMarts.

Each grid cell contains one of the following values:

  • ' ' represents an open road.
  • 'X' represents a blocked road that cannot be entered or crossed during travel.
  • 'D' represents a DashMart.

For each location in locations, return the shortest number of orthogonal steps needed to reach any DashMart. A step may move up, down, left, or right.

Apply these rules to every query:

  • A location outside the grid has distance -1.
  • A location on a DashMart has distance 0.
  • A location on an open road may travel only through open roads and DashMarts.
  • A location on a blocked road may take one first step to an orthogonally adjacent open road or DashMart. After leaving that starting cell, it may travel only through open roads and DashMarts. No route may enter any blocked road, including the starting cell again.
  • If no DashMart is reachable under these rules, the distance is -1.

Locations use [row, col] coordinates. Return the distances in the same order as the queries.

Function

closestDashMart(city: char[][], locations: int[][]) → int[]

Examples

Example 1

city = [
  ['X', ' ', ' ', 'D', ' ', ' ', 'X', ' ', 'X'],
  ['X', ' ', 'X', 'X', ' ', ' ', ' ', ' ', 'X'],
  [' ', ' ', ' ', 'D', 'X', 'X', ' ', 'X', ' '],
  [' ', ' ', ' ', 'D', ' ', 'X', ' ', ' ', ' '],
  [' ', ' ', ' ', ' ', ' ', 'X', ' ', ' ', 'X'],
  [' ', ' ', ' ', ' ', 'X', ' ', ' ', 'X', 'X']
]locations = [[200, 200], [1, 4], [0, 3], [5, 8], [1, 8], [5, 5]]return = [-1, 2, 0, -1, 6, 9]
city
0123456780X D X X1X XX X2 DXX X 3 D X 4 X X5 X XX

[200, 200] is outside the grid, so its result is -1. From [1, 4], the closest DashMart is two steps away at [0, 3]. The location [0, 3] is already a DashMart, so its distance is 0.

Both [5, 8] and [1, 8] are blocked cells. The cell [5, 8] has no adjacent traversable cell from which a DashMart can be reached, so its result is -1. From [1, 8], leave the blocked starting cell through [1, 7], then follow open roads to [0, 3] in a total of 6 steps.

From [5, 5], a shortest open-road route reaches [0, 3] in 9 steps.

Constraints

  • city.length >= 1.
  • Every row of city has the same positive length.
  • Every cell of city is ' ', 'X', or 'D'.
  • locations.length >= 0.
  • Every element of locations contains exactly two integers, [row, col].
  • A query coordinate may be outside the city grid.

More DoorDash Phone Screen questions

  • Warehouse Order PrioritizationPHONE SCREEN · Seen Nov 2026
  • Dasher Pay with Store Waits and Peak HoursPHONE SCREEN · Seen Nov 2026
  • Customer Bootstrap APIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dasher Active TimePHONE SCREEN · Seen Sep 2026
  • Merchant Capacity Interval MergePHONE SCREEN · Seen Aug 2026
  • Open Restaurants in a City RangePHONE SCREEN · Seen Aug 2026
  • Maximize Total Profit by Assigning Chefs to DishesPHONE SCREEN · Seen May 2026
  • Minimum Batches Within a Time WindowPHONE SCREEN · Seen Feb 2026
  • Minimum Riders for Delivery IntervalsPHONE SCREEN · Seen Feb 2026
  • Return Priority of Order IDsPHONE SCREEN · Seen Jun 2025

Similar questions at other companies

  • Simulate Orchard Rot SpreadAirbnb · OAAirbnb interview questions
  • Matrix EscapeByteDance · PHONE SCREENByteDance interview questions
  • Simulate Orchard Rot SpreadCapital One · OACapital One interview questions
  • Minimum Time to Spread Through a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
  • Word Chain Jumps in a GridGoogle · PHONE SCREENGoogle interview questions
  • Grid Infection with Recovery After D DaysOpenAI · PHONE SCREENOpenAI interview questions
  • Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
  • Shortest Path in a Blocked GridSpotify · PHONE SCREEN
  • Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions

DoorDash interview experiences

  • DoorDash SWE Onsite: Donation System Design: 1 Experience
  • DoorDash SWE Phone Screen: Bootstrap API in Java: 1 Experience
  • DoorDash SWE Virtual Onsite: 1 Experience
  • DoorDash SWE Phone Screen: Bootstrap API Parsing: 1 Experience
  • DoorDash Senior SWE Onsite Interview Experience: 1 Experience
  • DoorDash AI CodeCraft Interview: 8 Experiences
All DoorDash interview questionsSee DoorDash hiring insights
Saved
class Solution {
    public int[] closestDashMart(char[][] city, int[][] locations) {
      // write your code here
    }

}
Checking account…