Problem: Given a matrix of dimension m*n. There are x number of penguins standing on some cell(i,j) in the matrix initially. And there are some safe spots/cells in the matrix. Our job is figure out the minimum time for penguins to reach the safe spot with following conditions:↵
↵
1. If a spot is already taken by some penguin, any other penguin cannot take that spot.↵
2. While traversing, If some penguin passes through cell (i,j) in its path to reach some safe spot, it is banned for other penguins to use that cell.↵
↵
↵
Print -1 in case if it not possible for all penguins to reach to some safe spot.↵
↵
Penguins can move in four directions i.e either up, down, left, right.↵
All penguins can move to one of the adjacent cells in 1 unit of time.↵
↵
Let me know if the problem statement is not clear.↵
↵
↵
Would love to hear about your approach.
↵
1. If a spot is already taken by some penguin, any other penguin cannot take that spot.↵
2. While traversing, If some penguin passes through cell (i,j) in its path to reach some safe spot, it is banned for other penguins to use that cell.↵
↵
↵
Print -1 in case if it not possible for all penguins to reach to some safe spot.↵
↵
Penguins can move in four directions i.e either up, down, left, right.↵
All penguins can move to one of the adjacent cells in 1 unit of time.↵
↵
Let me know if the problem statement is not clear.↵
↵
↵
Would love to hear about your approach.