Tap here to switch tabs
Problem
Submissions

Problem: Shortest Path to Get Food

Try to solve the Shortest Path to Get Food problem.

Statement

You are given an m×nm \times n character matrix grid, representing a map with the following cell types:

  • '*': Your starting position. There is exactly 11 such cell.

  • '#': A food cell. There may be multiple food cells.

  • 'O': An empty cell that you can freely walk through.

  • 'X': An obstacle that you cannot pass through.

You may move from a cell to any adjacent cell vertically or horizontally (up, down, left, or right) in 11 step, provided the destination cell is within the bounds of grid and is not an obstacle.

Return the minimum number of steps required to reach any food cell from your starting position. If it is impossible to reach any food cell, return −1-1.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1≤m,n≤2001 \leq m, n \leq 200

  • grid[row][col] is '*', 'X', 'O', or '#'.

  • The grid contains exactly 11 '*'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Shortest Path to Get Food

Try to solve the Shortest Path to Get Food problem.

Statement

You are given an m×nm \times n character matrix grid, representing a map with the following cell types:

  • '*': Your starting position. There is exactly 11 such cell.

  • '#': A food cell. There may be multiple food cells.

  • 'O': An empty cell that you can freely walk through.

  • 'X': An obstacle that you cannot pass through.

You may move from a cell to any adjacent cell vertically or horizontally (up, down, left, or right) in 11 step, provided the destination cell is within the bounds of grid and is not an obstacle.

Return the minimum number of steps required to reach any food cell from your starting position. If it is impossible to reach any food cell, return −1-1.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1≤m,n≤2001 \leq m, n \leq 200

  • grid[row][col] is '*', 'X', 'O', or '#'.

  • The grid contains exactly 11 '*'.