#3552
Grid Teleportation Traversal
expert · 1175 · lc medium +32 · 23.3% accepted · 135 likes · top 3%
Description
Navigate a character grid from top-left (0,0) to bottom-right (m-1, n-1). Cells are empty (\'.\'), obstacles (\'#\'), or portals (uppercase letters). Moves (up/down/left/right) cost 1 each; obstacles are impassable.
When first entering a portal cell, you may instantly jump to any other cell sharing that letter (no cost, usable once per letter).
Return the minimum moves to reach the destination, or -1 if impossible.
Code
1
2
3