we have a matrix represented as 2d array of chars, on which there is:
A single cell where dog sits initially, marked as 'M'.
A single goat's den where the dog wants to get to, marked as 'D'.
Multiple grass cells, marked as 'G'.
Multiple tree cells, marked as 'T'
Multiple hive cells with bees, marked as 'H'.
Rules are the following:
- Every minute a dog can go to a neighbor cell on the north, south, east, west if this cell is not a tree.
- Every minute a bee hive can expand to a neighbor cell on the north, south, east, west if this cell is not a tree and is not a dog's den. The bees are standing in the original position as well.
Goal
Find the maximum number of minutes the dog can sit before stating moving so that he can get to the dog's den safely without meeting the bees on his path.
Example 1
MGGD
GGGG
GGGG
GHGG
answer: 1. The dog can stay in place for at most one minute, otherwise it will be touched by bees if it is late. Can someone please help solving this question?