Back to problems

Shortest Path with Gas Stations

Algorithm · Bloomberg · Medium

You are given an m x n grid representing a map. Each cell is one of the following: '.' – an empty, passable cell. '#' – a blocked cell (an obstacle you cannot enter). 'S' – the starting location (exactly one exists on the grid). 'D' – the destination (exactly one exists). 'G' – a gas station, which is passable (zero or more may appear). You also receive an integer fuelCapacity. You begin at 'S' with a completely full fuel tank holding fuelCapacity units of fuel. You may move…

Checking your access…