← Questions

Shortest path to collect all keys

0
AirbnbCodingLast asked Aug 2025

A grid has walls, a start cell, keys (lowercase letters) and locks (the matching uppercase letters). A lock can only be passed once you hold its key. Return the fewest steps to collect every key, or -1. Run a breadth-first search over states made of the position and the set of keys held, stored as a bitmask.

Write and test your solution herePython in your browser, the question's tests level by level, saved for you.Sign in to start coding