`{"id":"a5de9d09-609b-494d-93fa-728a2f8431f0","name":"Exit Point Of A Matrix","description":"1. You are given a number n, representing the number of rows.\r\n2. You are given a number m, representing the number of columns.\r\n3. You are given n*m numbers (1's and 0's), representing elements of 2d array a.\r\n4. Consider this array a maze and a player enters from top-left corner in east direction.\r\n5. The player moves in the same direction as long as he meets '0'. On seeing a 1, he takes a 90 deg right turn.\r\n6. You are required to print the indices in (row, col) format of the point from where you exit the matrix.","inputFormat":"A number n\r\nA number m\r\ne11\r\ne12..\r\ne21\r\ne22..\r\n.. n * m number of elements","outputFormat":"row\r\ncol (of the point of exit)","constraints":"1 &lt;= n &lt;= 10^2\r\n1 &lt;= m &lt;= 10^2\r\ne1, e2, .. n * m elements belongs to the set (0, 1)","sampleCode":{"cpp":{"code":"#include <iostream>\nusing namespace std;\n\n\nconst int mr = 100, mc = 100;\n\nint** input(int** mat, int n, int m)\n{\n mat = new int* [n];\n for (int i = 0; i < n; i++)\n {\n int* arr = new int[m];\n for (int j = 0; j < m; j++)\n {\n cin >> arr[j];\n }\n mat[i] = arr;\n }\n return mat;\n}\n\n\nint main(int argc, char** argv)\n{\n int n, m;\n cin >> n >> m;\n int** mat = input(mat, n, m);\n\n // write your code here \n \n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"python":{"code":"n= int(input())\nm= int(input())\narr = []\nfor i in range(n): \n a=[]\n for j in range(m):\n a.append(int(input()));\n arr.append(a)\n\n\n# write your code here"}},"points":10,"difficulty":"easy","sampleInput":"4\r\n4\r\n0\r\n0\r\n1\r\n0\r\n1\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n1\r\n0\r\n1\r\n0","sampleOutput":"1\r\n3","questionVideo":"https://www.youtube.com/embed/FnywCfCcMRk","hints":[],"associated":[{"id":"058ac294-6107-4929-b71c-039e71c0cc66","name":"What you have to do to move in south direction ?","slug":"what-you-have-to-do-to-move-in-south-direction","type":4},{"id":"230ba4e5-b9b8-4626-b585-071c20bd9286","name":"What is the space complexity of \"Exit Point Of A Matrix\"?","slug":"what-is-the-space-complexity-of-exit-point-of-a-matrix","type":4},{"id":"3964a199-e1ed-40fe-9d3b-a17cef0445bb","name":"What is the time complexity of \"Exit Point Of A Matrix\"?","slug":"what-is-the-time-complexity-of-exit-point-of-a-matrix","type":4},{"id":"d932304b-a56d-43e6-9676-be2c6063d8c2","name":"Which direction you go if you subtract 1 from j ?","slug":"which-direction-you-go-if-you-subtract-1-from-j","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f185374c-5448-476e-93e8-c4a4e9d1d520","name":"2D Arrays","slug":"2d-arrays-9999","type":0},{"id":"b204f226-d30f-4566-a762-6a9de22c4a9f","name":"Exit Point Of A Matrix","slug":"exit-point-of-a-matrix","type":1}],"next":{"id":"362c4ba8-b971-4aa8-8d30-a6c3b9768b0e","name":"Exit Point of a Matrix","type":3,"slug":"exit-point-of-a-matrix"},"prev":{"id":"07eb9868-2299-40ad-8c64-d920da732845","name":"Spiral Display","type":3,"slug":"spiral-display"}}}`

# Exit Point Of A Matrix

1. You are given a number n, representing the number of rows. 2. You are given a number m, representing the number of columns. 3. You are given n*m numbers (1's and 0's), representing elements of 2d array a. 4. Consider this array a maze and a player enters from top-left corner in east direction. 5. The player moves in the same direction as long as he meets '0'. On seeing a 1, he takes a 90 deg right turn. 6. You are required to print the indices in (row, col) format of the point from where you exit the matrix.

`{"id":"a5de9d09-609b-494d-93fa-728a2f8431f0","name":"Exit Point Of A Matrix","description":"1. You are given a number n, representing the number of rows.\r\n2. You are given a number m, representing the number of columns.\r\n3. You are given n*m numbers (1's and 0's), representing elements of 2d array a.\r\n4. Consider this array a maze and a player enters from top-left corner in east direction.\r\n5. The player moves in the same direction as long as he meets '0'. On seeing a 1, he takes a 90 deg right turn.\r\n6. You are required to print the indices in (row, col) format of the point from where you exit the matrix.","inputFormat":"A number n\r\nA number m\r\ne11\r\ne12..\r\ne21\r\ne22..\r\n.. n * m number of elements","outputFormat":"row\r\ncol (of the point of exit)","constraints":"1 &lt;= n &lt;= 10^2\r\n1 &lt;= m &lt;= 10^2\r\ne1, e2, .. n * m elements belongs to the set (0, 1)","sampleCode":{"cpp":{"code":"#include <iostream>\nusing namespace std;\n\n\nconst int mr = 100, mc = 100;\n\nint** input(int** mat, int n, int m)\n{\n mat = new int* [n];\n for (int i = 0; i < n; i++)\n {\n int* arr = new int[m];\n for (int j = 0; j < m; j++)\n {\n cin >> arr[j];\n }\n mat[i] = arr;\n }\n return mat;\n}\n\n\nint main(int argc, char** argv)\n{\n int n, m;\n cin >> n >> m;\n int** mat = input(mat, n, m);\n\n // write your code here \n \n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"python":{"code":"n= int(input())\nm= int(input())\narr = []\nfor i in range(n): \n a=[]\n for j in range(m):\n a.append(int(input()));\n arr.append(a)\n\n\n# write your code here"}},"points":10,"difficulty":"easy","sampleInput":"4\r\n4\r\n0\r\n0\r\n1\r\n0\r\n1\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n1\r\n0\r\n1\r\n0","sampleOutput":"1\r\n3","questionVideo":"https://www.youtube.com/embed/FnywCfCcMRk","hints":[],"associated":[{"id":"058ac294-6107-4929-b71c-039e71c0cc66","name":"What you have to do to move in south direction ?","slug":"what-you-have-to-do-to-move-in-south-direction","type":4},{"id":"230ba4e5-b9b8-4626-b585-071c20bd9286","name":"What is the space complexity of \"Exit Point Of A Matrix\"?","slug":"what-is-the-space-complexity-of-exit-point-of-a-matrix","type":4},{"id":"3964a199-e1ed-40fe-9d3b-a17cef0445bb","name":"What is the time complexity of \"Exit Point Of A Matrix\"?","slug":"what-is-the-time-complexity-of-exit-point-of-a-matrix","type":4},{"id":"d932304b-a56d-43e6-9676-be2c6063d8c2","name":"Which direction you go if you subtract 1 from j ?","slug":"which-direction-you-go-if-you-subtract-1-from-j","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f185374c-5448-476e-93e8-c4a4e9d1d520","name":"2D Arrays","slug":"2d-arrays-9999","type":0},{"id":"b204f226-d30f-4566-a762-6a9de22c4a9f","name":"Exit Point Of A Matrix","slug":"exit-point-of-a-matrix","type":1}],"next":{"id":"362c4ba8-b971-4aa8-8d30-a6c3b9768b0e","name":"Exit Point of a Matrix","type":3,"slug":"exit-point-of-a-matrix"},"prev":{"id":"07eb9868-2299-40ad-8c64-d920da732845","name":"Spiral Display","type":3,"slug":"spiral-display"}}}` Editor

# Exit Point Of A Matrix

easy

1. You are given a number n, representing the number of rows. 2. You are given a number m, representing the number of columns. 3. You are given n*m numbers (1's and 0's), representing elements of 2d array a. 4. Consider this array a maze and a player enters from top-left corner in east direction. 5. The player moves in the same direction as long as he meets '0'. On seeing a 1, he takes a 90 deg right turn. 6. You are required to print the indices in (row, col) format of the point from where you exit the matrix.

## Constraints

1 <= n <= 10^2 1 <= m <= 10^2 e1, e2, .. n * m elements belongs to the set (0, 1)

## Format

### Input

A number n A number m e11 e12.. e21 e22.. .. n * m number of elements

### Output

row col (of the point of exit)

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}4 4 0 0 1 0 1 0 0 0 0 0 0 0 1 0 1 0```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}1 3```

Question Video

Discussions

Show Discussion

Related Resources 