Portal grid shortest path
Your task
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.
Examples
portal_shortest(grid: list[str]) -> intExample 1
Input
portal_shortest(["S.A..", "#####", "..A.E"])Output
5