← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
You are given a 2-D grid that represents a city map. Each cell can be one of three characters:
You may move only up, down, left, or right (no diagonals) and you cannot leave the grid. Your task is to pre-compute, for every open road cell, the shortest travel distance to the nearest DashMart. If a cell is itself a DashMart the distance is 0; if a cell is blocked or unreachable from every DashMart its distance remains infinity (represented as -1 in output). After the pre-processing you must be able to answer many client queries in O(1) time each: given a specific row and column, return the shortest distance you computed, or -1 if none exists.