Shortest Path to Get All Keys

You are given an m x n grid where each cell is one of:

  • @ is the starting position (exactly one cell).
  • . is an empty passable cell.
  • # is a wall.
  • a to f are keys. Stepping on a key collects it automatically.
  • A to F are locks. A lock cell is passable only while you hold the matching key (a unlocks A).

In one step you may move up, down, left, or right to an adjacent cell. Return the minimum number of steps needed to collect every key on the grid, or -1 if it is impossible.

Examples
Input: ["@.a.","##b#","A.B."]
Output: 3
Hints

Shortest Path to Get All Keys

You are given an `m x n` grid where each cell is one of: