Skip to content

Latest commit

 

History

History
49 lines (40 loc) · 1.27 KB

File metadata and controls

49 lines (40 loc) · 1.27 KB
  • You are starving and you want to eat food as quickly as possible. You want to find the shortest path to arrive at a food cell.

You are given an m x n character matrix, grid, of these different types of cells:

  • 'P' is your location. There is exactly one '*' cell.
  • 'F' is a food cell. There may be multiple food cells.
  • 'O' is free space, and you can travel through these cells.
  • 'X' is an obstacle, and you cannot travel through these cells.

Return the length of the shortest path for you to reach any food cell. If there is no path for you to reach food, return -1.

  • Example:
        Input: X X X X X X X X
               X P O X O F O X
               X O O X O O X X
               X O O O O F O X
               X X X X X X X X
        Output: 3
        Explanation: It takes 3 steps to reach the food.
  • Input:
        X X X X X X
        X P O O O X
        X O O F O X
        X X X X X X
  • Output:
        3

Running

  • Running an instance:
    python main.py "path_instance"
  • Example: running an instance "input1":
    python main.py instances/input1