can anybody tell the approach?

Revision en2, by DebuggingMyLife, 2021-10-29 07:06:04

Bob wants to play game named Easter Diablo Maze. The game is set in a R x C grid having wall and ghosts which replicate every second, touching ghost kills the droid. The score of the game is determined by the number of seconds the droid survives Rules of the game are as follows:

  1. Each cell in the grid is empty or contains wall.

  2. Some cell contains ghosts, they multiply after every second to all of its adjacent empty cells (cell that share an edge are called adjacent)

  3. droid and ghost cannot jump a wall.

  4. droid is free to move to it's adjacent empty cells

  5. Game ends when ghost fills the droid's cell.

Return the maximum time that the droid survives in the game or -1 if droid can survive indefinitely

If the cell value(val):

1.) val = 1 — cell contain wall
2.) val = 0 — cell is empty
3.) val = 3 — initial location of Droid
4.) val = 5 — location of Ghost

Constraints: 1<= R <=100 and 1<= C <=100
Example — 1:
3 3
5 0 0
0 3 0
0 0 0
Ans: 4
Example — 2:

5 5
5 0 0 1 0
0 5 0 1 0
0 0 0 1 0
1 1 1 0 0
0 0 0 3 0
Ans: -1

Tags graph, dfs/bfs

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English DebuggingMyLife 2021-10-29 07:06:04 4 Tiny change: 'pty cells 5. Game en' -> 'pty cells \n\n5. Game en'
en1 English DebuggingMyLife 2021-10-29 06:44:48 1244 Initial revision (published)