Problem library

Breach Run

Hard
graphsbfs

The arena is a grid of strings where . is open floor and # is a wall. You start in the top-left cell and must reach the bottom-right cell (both are always open), moving one cell up, down, left or right per step.

You carry charges breaching charges. Moving into a wall cell uses one charge. Return the fewest steps needed to reach the exit, or -1 if it cannot be reached.

Examples

Input: grid = ["..#","##.","..."], charges = 0
Output: -1
Input: grid = [".##","###","##."], charges = 1
Output: -1