Code Room
CodingHardcod-g736
Subject Shortest pathLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development, Computer games

Question

A grid contains 'S' start, 'T' target, '.' floor, '#' wall, and matched portal pairs marked by lowercase letters (each letter appears on at most two cells). A normal step to an orthogonally adjacent non-wall cell costs 1. Standing on a portal cell, you may teleport instantly (cost 0) to the other cell with the same letter. Return the minimum cost to get from 'S' to 'T', or -1 if unreachable. Exactly one 'S' and one 'T' exist.

Implement
min_steps_portals(grid: list[list[str]]) → int
Examples
in[[["S",".","a","#","#","#","a",".","T"]]]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.