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

Question

In a grid of characters, '.' is an open cell, '#' is a wall, '@' is your start, a lowercase letter is a key, and the matching uppercase letter is a locked door you can only pass once you hold that key. You move up/down/left/right one cell per step. Starting at '@', return the fewest steps to collect every key on the board (you may pass through doors only after picking up their key). Return -1 if it is impossible to collect all keys. Keys use distinct letters from 'a' to 'f' (at most 6).

Implement
shortest_path_keys(grid: list[str]) → int
Examples
in[["@.a.A.b"]]out6
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.