
If Ninja is unable to reach his friend’s house then return -1.
Empty cell in the matrix is represented by ‘0’ and an obstacle by ‘1’.
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains three space-separated integers, 'N' and 'M', denoting the number of rows and columns in the matrix 'MAT', respectively and ‘K’, denoting the atmost numbers of obstacles Ninja can remove.
Each of the next 'N' lines contains 'M' space-separated integers denoting the matrix 'MAT' elements.
For each test case, print a single line containing a single integer denoting the minimum number of steps needed to reach Ninja’s friend's house from Ninja house.
The output of each test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N, M <= 50
1<= K <= N * M
0 <= MAT[ i ][ j ] <= 1
Where 'T' denotes the number of test cases, 'N' and 'M' denotes the number of rows and columns in the matrix 'MAT' respectively, 'K' denotes the most numbers of obstacles Ninja can remove and 'MAT[i][j]' denotes the element present at the 'i'th' row and the 'j'th' column of the matrix 'MAT'.
Time limit: 1 sec.
The idea here is that we will use simple BFS(breadth first search) but with extra conditions that we can only move to the next cell when ‘k’ value is greater than 0.
We need to store the values of already used k i.e. ninja's secret technique.
We create a queue that can store 4 things i.e position, steps and k used.
Algorithm: