Code RoomGrid shortest path with portals
HardPrep Room Coding #1301

Grid shortest path with portals

CodingAlgorithms & data structuresSenior–Staff~35 min

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.

0:00 of about 35 min
InputExpectedGot
[[["S",".","a","#","#","#","a",".","T"]]]4not run yetsample