Exit Point in a Matrix
Easy Accuracy: 44.03% Submissions: 5089 Points: 2

Given a matrix with 0’s and 1’s , you enter the matrix at cell (0,0) in left to right direction. whenever you encounter a 0 you retain in same direction , if you encounter a 1’s you have to change direction to right of current direction and change that 1 value to 0, you have to find out from which index you will leave the matrix at the end.

The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains two lines . The first line of each test case contains two integers n and m denoting the size of the matrix. Then in the next line are n*m space separated values of the matrix.

For each test case print in a new line two integers separated by space denoting the index of the matrix from which you will leave the matrix at the end.



3 3
0 0 1 0 0 0 0 0 0
2 4
0 0 0 1 0 0 1 1

2 2 
0 2


to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.