← 返回 doordash 的题目列表Dashmart Shortest Path
类型:online_judge
Given a matrix representing the map around a Dashmart, where '0' represents an empty space, '1' represents an obstacle, 'S' represents the start point, and 'E' represents a Dashmart. Determine the shortest path from the start point to a Dashmart (return -1 if no valid path exists). Implement a function to compute the length of this path.
Additionally, the code should be extensible to handle situations with multiple Dashmarts, meaning the shortest path from the start point S to multiple Dashmarts should return the shortest reachable path length.
Example
Input:
[['S', '0', '1', 'E'],
['E', '1', '0', '0'],
['0', '1', '0', 'E'],
['0', '0', '0', '0']]
Output: 2
Constraints
Matrix size m x n, where 1 <= m, n <= 100
There is guaranteed to be exactly one 'S' in the matrix
The number of Dashmarts can be one or multiple
Example
Input
[['S', '0', '1', 'E'], ['E', '1', '0', '0'], ['0', '1', '0', 'E'], ['0', '0', '0', '0']]
Output
2