Shortest path through a maze with free portals
Your task
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.
Examples
portal_maze(grid: list[str]) -> intExample 1
Input
portal_maze(["S.a..", "###.#", "E.a.."])Output
4