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

Question

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