Code Room
CodingHardcod-g505
Subject Grid traversalLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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]) → int
Examples
in[["S.a..","###.#","E.a.."]]out4
What 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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.