Collect all keys
Given a grid of characters where '.' is open, '#' is a wall, '@' is the single start, lowercase 'a'..'f' are keys, and uppercase 'A'..'F' are matching locked doors, return the fewest moves (up/down/left/right) to collect every key that exists in the grid. You may walk over a key cell to pick it up; you may only enter a door cell if you already hold its matching key. Return -1 if collecting all keys is impossible. There are at most 6 distinct keys.
Implement
shortest_path_all_keys(grid: list[str]) → intExamples
in
[["@.a.#","###.#","b.A.B"]]out8What 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
solution.py
InputExpectedGot
[["@.a.#","###.#","b.A.B"]]8not run yetsample