Warehouse Route Optimizer - Problem
You're managing a large warehouse with a complex grid layout where delivery robots need to find the shortest path from a starting position to a destination. The warehouse has several complications:
Grid Constraints:
0represents open corridors where robots can move freely-1represents blocked sections (walls, shelves, obstacles)- Positive integers represent weighted corridors with movement costs
Movement Rules:
- Robots can move in 4 directions (up, down, left, right)
- Some paths may be one-way based on conveyor belts or traffic flow
- Movement cost from cell A to cell B is determined by the destination cell's weight
Given a warehouse grid, starting position, and destination position, find the minimum total cost to reach the destination. If no path exists, return -1.
Input & Output
Example 1 — Basic Warehouse Grid
$
Input:
grid = [[0,1,2],[1,0,3],[2,3,0]], start = [0,0], end = [2,2]
›
Output:
6
💡 Note:
Optimal path: (0,0) → (1,0) → (2,1) → (2,2). Cost = 0 + 1 + 3 + 0 = 4. Wait, let me recalculate: movement cost is destination cell's weight, so (0,0)→(1,0) costs 1, (1,0)→(2,0) costs 2, (2,0)→(2,1) costs 3, (2,1)→(2,2) costs 0. Total = 1+2+3 = 6.
Example 2 — Blocked Path
$
Input:
grid = [[0,1,-1],[1,-1,2],[3,2,0]], start = [0,0], end = [2,2]
›
Output:
9
💡 Note:
Direct path blocked by -1 cells. Must go: (0,0) → (0,1) → (1,0) → (2,0) → (2,1) → (2,2). Cost = 1 + 1 + 3 + 2 + 0 = 7. Actually, checking valid moves more carefully: (0,0)→(1,0) costs 1, then (1,0)→(2,0) costs 3, then (2,0)→(2,1) costs 2, then (2,1)→(2,2) costs 0. Total = 6. Or (0,0)→(0,1) costs 1, but (0,1)→(1,1) blocked. Let me trace: viable path is (0,0)→(1,0)→(2,0)→(2,1)→(2,2) = 1+3+2+0 = 6.
Example 3 — No Path Available
$
Input:
grid = [[0,-1],[−1,0]], start = [0,0], end = [1,1]
›
Output:
-1
💡 Note:
All adjacent cells to start (0,0) are blocked (-1), so no path exists to reach destination (1,1).
Constraints
- 1 ≤ grid.length, grid[0].length ≤ 100
- -1 ≤ grid[i][j] ≤ 1000
- 0 ≤ start[0], start[1] < grid.length
- 0 ≤ end[0], end[1] < grid.length
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code