Myntra Delivery Route
At Myntra, efficient logistics are crucial for timely deliveries. Imagine a large warehouse where delivery agents navigate through aisles and storage areas. This problem simulates a scenario where an agent needs to pick up a package component from a specific station before heading to the final delivery drop-off point, all while avoiding obstacles. Your task is to find the most efficient route.
Implement a function findMinDeliverySteps that calculates the minimum number of steps required for a delivery agent to complete a specific route in a warehouse.
Input:
warehouseLayout: A string[][] (or char[][]) representing the 2D grid of the warehouse.
Output:
number representing the minimum total steps required to travel from 'S' to 'P' and then from 'P' to 'D'. Return -1 if any part of the journey is impossible.Examples
Example 1
Input:
warehouseLayout = [["S", ".", "."], [".", "#", "P"], [".", ".", "D"]]
Output:
4
Note:
Path S->P: S(0,0) -> (0,1) -> (0,2) -> P(1,2) takes 3 steps. Path P->D: P(1,2) -> D(2,2) takes 1 step. Total steps: 3 + 1 = 4.
Example 2
Input:
warehouseLayout = [["S", "#", "."], ["#", "#", "P"], [".", "#", "D"]]
Output:
-1
Note:
It's impossible to reach 'P' from 'S' due to obstacles.
Example 3
Input:
warehouseLayout = [["S", ".", ".", "."], [".", "#", ".", "P"], ["#", ".", ".", "."], [".", ".", ".", "D"]]
Output:
6
Note:
Path S->P: S(0,0) -> (0,1) -> (0,2) -> (0,3) -> P(1,3) takes 4 steps. Path P->D: P(1,3) -> (2,3) -> D(3,3) takes 2 steps. Total steps: 4 + 2 = 6.
Constraints
warehouseLayout will have M rows and N columns.1 <= M, N <= 100warehouseLayout will contain one of 'S', 'P', 'D', '#', '.'.Loading editor...