Teleport Maze
Hard
bfs
graph
teleportation
shortest-path
Problem Description
Navigate a maze with teleportation portals. The maze has walls (#), paths (.), start (S), end (E), and teleport portals marked with letters (A-Z). Portals with the same letter are connected and allow instant teleportation between them.
Input Format
First line contains m and n (maze dimensions). Next m lines contain the maze with characters: S (start), E (end), # (wall), . (path), A-Z (portals).
Output Format
Minimum steps to reach end from start, or -1 if impossible.
Constraints
• 1 ≤ m, n ≤ 50
• Exactly one S and one E
• Teleportation between same letters is instant (0 steps)
• Regular movement takes 1 step
• Can have multiple portal pairs
Sample Input/Output
Input:
4 5 S.#.E ..#.. A.#.B A...B
Output:
4
Explanation
Path: S→(0,1)→A(2,0)→teleport to A(3,0)→(3,1)→(3,2)→(3,3)→B(3,4)→teleport to B(2,4)→E(0,4). Steps: 4.
Solution Hints
150
Points
Points
4000ms
Time Limit
Time Limit
512MB
Memory Limit
Memory Limit
Code Editor
Register to Access Code Editor
Create a free account to solve coding problems and track your progress.
Register Now