CT052

Pikachu’s Lantern Maze

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Pikachu has to carry a glowing lantern through a tiled maze. Walls are blocked; find the fewest orthogonal moves from S to T, or report that the lantern cannot reach it. Input: rows cols, followed by rows strings of #, ., S, T. Output: shortest move count, or -1.

Example 1:

Input: 3 4 S..# .#.. ...T
Output: 5

Example 2:

Input: 2 3 S#T ...
Output: 4

Example 3:

Input: 1 2 ST
Output: 1

Constraints:

1≤rows,cols≤1000; exactly one S and T.

Tags:

graphs bfs grid
Loading...
Test Cases:No test cases
No test cases available.