Portal grid shortest path
Given a grid of characters: 'S' is the start, 'E' is the exit, '#' is a wall, '.' is open floor, and any other letter denotes a teleport portal. You move up/down/left/right between non-wall cells, each step costing 1. Additionally, when you are standing on a portal cell you may, as a single step, teleport to any other cell sharing the same letter. Return the minimum number of steps from S to E, or -1 if unreachable. Assume each portal letter appears at most twice.
Implement
portal_shortest(grid: list[str]) → intExamples
in
[["S.A..","#####","..A.E"]]out5What 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..","#####","..A.E"]]5not run yetsample