Trains the technique from
LeetCode 864Shortest Path to Get All KeysThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A splice crew has a floor plan of an underground utility vault, handed over as vault: a list of equal-length strings, one per row, read top to bottom and left to right.
Each character says what is in that cell:
"@" is the access hatch the crew climbs in through. Exactly one cell holds it."." is bare floor."#" is solid rock.From the cell it stands on the crew may step to the cell directly above, below, left or right. Each such step counts as one move. It may never step outside the plan and never into rock. Stepping onto a wrench picks it up at no cost, and a wrench once picked up is carried for the rest of the run. Stepping onto a gate is only allowed while carrying its matching wrench, and costs nothing beyond the step itself; the gate stays open afterwards. Bare floor and the hatch cell are always free to step on.
Return the fewest moves needed until the crew is carrying every wrench on the plan. Return -1 when no sequence of moves collects them all.
Example 1
One run of eight moves works: three steps east onto wrench `"a"`, one step back west, two steps south through gate `"A"`, then two steps west onto wrench `"b"`.
Example 2
Rock sits east and south of the hatch, so the crew cannot take a single step and wrench `"a"` is never reached.
Example 3
Three wrenches lie on this plan and a run of fourteen moves ends with all three in hand, having opened gates `"A"` and `"B"` along the way.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def fewest_moves_for_wrenches(vault: list[str]) -> int:public int fewestMovesForWrenches(String[] vault)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.