Code RoomCollect all keys in grid
HardPrep Room Coding #1068

Collect all keys in grid

CodingAlgorithms & data structuresSenior–Staff~40 min

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.

0:00 of about 40 min
InputExpectedGot
[["@.a.A.b"]]6not run yetsample