BugForge
DSA

Warehouse Robot Shortest Route

MediumBFSgrid 00:00

A robot moves on a grid: 'S' start, 'T' target, '#' shelf (blocked), '.' open. Each move goes one cell up/down/left/right. Return the minimum moves from S to T, or -1.

Signature

shortestRoute(grid: string[]) → int
Example 1
grid = ["S.#.","..#.","...T"]
output = 5
down, down, right ×3 = 5
Example 2
grid = ["S#","#T"]
output = -1
blocked → -1

Constraints

  • 1 ≤ rows, cols ≤ 500
  • exactly one S and one T
Run checks the examples. Submit runs every hidden test (17, including large inputs that catch slow solutions).