I was trying to solve the following question:↵
↵
You are playing a game in which you have a rectangular grid of nn cells. Each cell is either empty or has a firework. Empty cells are marked with ".", cells with firework are marked with "" . Two cells are said to be adjacent if they share a side.↵
↵
If firework in any cell explodes it destroys itself and the empty cells connected to it. Two cells are connected if there is a path of empty adjacent cells between them. You have to find the number of cells that will be destroyed if the fireworks are triggered independently. Input Constraints: 1≤n≤1000 Sample Input 4↵
↵
\* . . *↵
↵
. . * .↵
↵
\* . . *↵
↵
\* . . *↵
↵
Sample Output 66(9(for 1st *)+10+10+9+10+9+9(for 7th *)).↵
↵
I simply applied a BFS and added individual sum.The problem is that it only passed some test cases,wrong answer and time limit exceeded in some.Can some please suggest what test case am I missing in handling?↵
My code: https://gist.github.com/Sharma96/16071e66b0a36828c3566196289f0c92
↵
You are playing a game in which you have a rectangular grid of nn cells. Each cell is either empty or has a firework. Empty cells are marked with ".", cells with firework are marked with "" . Two cells are said to be adjacent if they share a side.↵
↵
If firework in any cell explodes it destroys itself and the empty cells connected to it. Two cells are connected if there is a path of empty adjacent cells between them. You have to find the number of cells that will be destroyed if the fireworks are triggered independently. Input Constraints: 1≤n≤1000 Sample Input 4↵
↵
\* . . *↵
↵
. . * .↵
↵
\* . . *↵
↵
\* . . *↵
↵
Sample Output 66(9(for 1st *)+10+10+9+10+9+9(for 7th *)).↵
↵
I simply applied a BFS and added individual sum.The problem is that it only passed some test cases,wrong answer and time limit exceeded in some.Can some please suggest what test case am I missing in handling?↵
My code: https://gist.github.com/Sharma96/16071e66b0a36828c3566196289f0c92