Portal grid shortest path
You're navigating a grid: 'S' is the start, 'E' the exit, '.' is walkable, '#' is a wall. Each lowercase letter marks a portal; portals that share the same letter are linked, and standing on one lets you teleport to its partner tile at no movement cost (exactly two tiles per letter). Walking to an orthogonally adjacent non-wall tile costs 1 step. Return the minimum number of steps to get from S to E, or -1 if unreachable.
Implement
portal_maze(grid: list[str]) → intExamples
in
[["S.a..","###.#","E.a.."]]out4What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 35 min
solution.py
InputExpectedGot
[["S.a..","###.#","E.a.."]]4not run yetsample