1> rotten mango (given q explanation and soln in cpp)

Given a matrix of dimension m*n where each cell in the matrix can have values 0, 1 or 2 which has the following meaning:

0: Empty cell
1: Cells have fresh oranges
2: Cells have rotten oranges

So we have to determine what is the minimum time required so that all the Mangoes become rotten. A rotten Mango at index [i,j] can rot other fresh Mango at indexes [i-1,j], [i+1,j], [i,j-1], [i,j+1] (up, down, left and right). If it is impossible to rot every Mango then simply return -1.
Input Format

The first line of input contains an integer T denoting the number of test cases. Each test case contains two integers r and c, where r is the number of rows and c is the number of columns in the array a[]. Next r lines contains space separated c elements each in the array a[].
Constraints

1<=T<=100
1<=r<=100
1<=c<=100
0<=a[i]<=2
Output Format

Print an integer which denotes the minimum time taken to rot all the Mangoes.(-1 if it is impossible).
Sample Input

2
3 5
2 1 0
2 1 1
0 1 2
1 1 0
0 2 1
3 5
2 1 0
2 1 0
0 1 2
1 1 0
0 2 1

Sample Output

2
-1

why no reply yet???

Hello @Kash-Moulik-3715574511847721 i am sorry for replying late. what is the problem that you are facing?

I TRIED BUT NOT ABLE TO GET RIGHT OUTPUT

@Kash-Moulik-3715574511847721 where is your code?
you can try this questiopn on gfg also.
it is available there as well.

You can see this code:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.