`{"id":"f1268d89-f5a6-46fc-bf37-117480fe634f","name":"The State Of Wakanda - 1","description":"The historic state of Wakanda has various monuments and souvenirs which are visited by many travelers every day. The guides follow a prescribed route of visiting the monuments which improve them understand the relevance of each monument. \r\n\r\nThe route of the monument is fixed and expressed in a 2-d matrix where the travelers visit the prescribed next monument. For example\r\n\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n\r\nis the prescribed route and the visitors travels this path: 1->2->3->4->5->6->7->8->9\r\n\r\nHowever, a certain visitor decides to travel a different path as follows: \r\n1. He first travels southwards till no further south places are available.\r\n2. He then moves only 1 place eastwards.\r\n3. He starts to move again towards north till any further north moves are available. \r\nThis continues till all the places are covered. \r\n\r\nFor example, the monuments are named as follows:\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n\r\nPath followed by traveler: 1->4->7->8->5->2->3->6->9\r\n\r\nYou are required to print the path that this traveler follows to visit all places.\r\n\r\n\r\n1. You will be given a number n, representing the number of rows.\r\n2. You will be given a number m, representing the number of columns.\r\n3. You will be given n*m numbers, representing elements of 2d arrays.\r\n\r\nNote - Please check the output format for details.","inputFormat":"A number n\r\nA number m\r\ne11\r\ne12..\r\ne21\r\ne22..\r\n.. n * m number of elements","outputFormat":"e11\r\ne12\r\ne13\r\n..\r\ne1n\r\ne2n\r\ne2n-1\r\n..\r\ne21\r\ne31\r\ne32\r\n..\r\ne3n\r\ne4n ..","constraints":"1 &lt;= n &lt;= 10^2\r\n1 &lt;= m &lt;= 10^2\r\n-10^9 &lt;= e1, e2, .. n * m elements &lt;= 10^9","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<vector>\n\nusing namespace std;\n\nvoid columnTraversal(vector<vector<int>> mat){\n// Write your code here.\n}\n\nint main(){\n int n;\n int m;\n cin>> n;\n cin>> m;\n \n vector<vector<int>> mat;\n for(int i= 0; i< n; i++){\n vector<int> arr;\n for(int j= 0; j< m; j++){\n int ele;\n cin>> ele;\n arr.push_back(ele);\n }\n mat.push_back(arr);\n }\n \n columnTraversal(mat);\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n\r\npublic static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"python":{"code":"def colTraversal(mat):\n# Write your code here.\n \n\nn= int(input())\nm= int(input())\n\nmat= []\nfor i in range (n):\n a= []\n for j in range (m):\n a.append(int(input()))\n mat.append(a)\n \ncolTraversal(mat)"}},"points":10,"difficulty":"easy","sampleInput":"3\r\n4\r\n11\r\n12\r\n13\r\n14\r\n21\r\n22\r\n23\r\n24\r\n31\r\n32\r\n33\r\n34","sampleOutput":"11\r\n21\r\n31\r\n32\r\n22\r\n12\r\n13\r\n23\r\n33\r\n34\r\n24\r\n14","questionVideo":"https://www.youtube.com/embed/nUUc9DKTBdY","hints":[],"associated":[{"id":"0fbfd140-4416-4ce1-8b5f-c1e54b4ca120","name":"(State of Wakanda) What is the time complexity for this solution ?","slug":"state-of-wakanda-what-is-the-time-complexity-for-this-solution","type":4},{"id":"864eb5ad-a72e-435f-b7fc-68253a9dd980","name":"(State of Wakanda) Can this problem be solved with recursion ?","slug":"state-of-wakanda-can-this-problem-be-solved-with-recursion","type":4},{"id":"c8c1fada-1fb7-4ff4-a7a6-6c31c6f91c5e","name":"(State of Wakanda) For what the outer loop should traverse ?","slug":"state-of-wakanda-for-what-the-outer-loop-should-traverse","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":"18ef05e6-7a41-480f-ad63-0dfe1c24eabd","name":"The State Of Wakanda - 1","slug":"the-state-of-wakanda-1","type":1}],"next":{"id":"d12f6857-1963-4fd6-af7b-e28a5f8e659c","name":"The State Of Wakanda -1","type":3,"slug":"the-state-of-wakanda-1"},"prev":{"id":"beea55a6-71b3-4ace-a46e-32baca36383f","name":"Matrix Multiplication","type":3,"slug":"matrix-multiplication"}}}`

# The State Of Wakanda - 1

The historic state of Wakanda has various monuments and souvenirs which are visited by many travelers every day. The guides follow a prescribed route of visiting the monuments which improve them understand the relevance of each monument. The route of the monument is fixed and expressed in a 2-d matrix where the travelers visit the prescribed next monument. For example 1 2 3 4 5 6 7 8 9 is the prescribed route and the visitors travels this path: 1->2->3->4->5->6->7->8->9 However, a certain visitor decides to travel a different path as follows: 1. He first travels southwards till no further south places are available. 2. He then moves only 1 place eastwards. 3. He starts to move again towards north till any further north moves are available. This continues till all the places are covered. For example, the monuments are named as follows: 1 2 3 4 5 6 7 8 9 Path followed by traveler: 1->4->7->8->5->2->3->6->9 You are required to print the path that this traveler follows to visit all places. 1. You will be given a number n, representing the number of rows. 2. You will be given a number m, representing the number of columns. 3. You will be given n*m numbers, representing elements of 2d arrays. Note - Please check the output format for details.

`{"id":"f1268d89-f5a6-46fc-bf37-117480fe634f","name":"The State Of Wakanda - 1","description":"The historic state of Wakanda has various monuments and souvenirs which are visited by many travelers every day. The guides follow a prescribed route of visiting the monuments which improve them understand the relevance of each monument. \r\n\r\nThe route of the monument is fixed and expressed in a 2-d matrix where the travelers visit the prescribed next monument. For example\r\n\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n\r\nis the prescribed route and the visitors travels this path: 1->2->3->4->5->6->7->8->9\r\n\r\nHowever, a certain visitor decides to travel a different path as follows: \r\n1. He first travels southwards till no further south places are available.\r\n2. He then moves only 1 place eastwards.\r\n3. He starts to move again towards north till any further north moves are available. \r\nThis continues till all the places are covered. \r\n\r\nFor example, the monuments are named as follows:\r\n1 2 3\r\n4 5 6\r\n7 8 9\r\n\r\nPath followed by traveler: 1->4->7->8->5->2->3->6->9\r\n\r\nYou are required to print the path that this traveler follows to visit all places.\r\n\r\n\r\n1. You will be given a number n, representing the number of rows.\r\n2. You will be given a number m, representing the number of columns.\r\n3. You will be given n*m numbers, representing elements of 2d arrays.\r\n\r\nNote - Please check the output format for details.","inputFormat":"A number n\r\nA number m\r\ne11\r\ne12..\r\ne21\r\ne22..\r\n.. n * m number of elements","outputFormat":"e11\r\ne12\r\ne13\r\n..\r\ne1n\r\ne2n\r\ne2n-1\r\n..\r\ne21\r\ne31\r\ne32\r\n..\r\ne3n\r\ne4n ..","constraints":"1 &lt;= n &lt;= 10^2\r\n1 &lt;= m &lt;= 10^2\r\n-10^9 &lt;= e1, e2, .. n * m elements &lt;= 10^9","sampleCode":{"cpp":{"code":"#include<iostream>\n#include<vector>\n\nusing namespace std;\n\nvoid columnTraversal(vector<vector<int>> mat){\n// Write your code here.\n}\n\nint main(){\n int n;\n int m;\n cin>> n;\n cin>> m;\n \n vector<vector<int>> mat;\n for(int i= 0; i< n; i++){\n vector<int> arr;\n for(int j= 0; j< m; j++){\n int ele;\n cin>> ele;\n arr.push_back(ele);\n }\n mat.push_back(arr);\n }\n \n columnTraversal(mat);\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n\r\npublic static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"python":{"code":"def colTraversal(mat):\n# Write your code here.\n \n\nn= int(input())\nm= int(input())\n\nmat= []\nfor i in range (n):\n a= []\n for j in range (m):\n a.append(int(input()))\n mat.append(a)\n \ncolTraversal(mat)"}},"points":10,"difficulty":"easy","sampleInput":"3\r\n4\r\n11\r\n12\r\n13\r\n14\r\n21\r\n22\r\n23\r\n24\r\n31\r\n32\r\n33\r\n34","sampleOutput":"11\r\n21\r\n31\r\n32\r\n22\r\n12\r\n13\r\n23\r\n33\r\n34\r\n24\r\n14","questionVideo":"https://www.youtube.com/embed/nUUc9DKTBdY","hints":[],"associated":[{"id":"0fbfd140-4416-4ce1-8b5f-c1e54b4ca120","name":"(State of Wakanda) What is the time complexity for this solution ?","slug":"state-of-wakanda-what-is-the-time-complexity-for-this-solution","type":4},{"id":"864eb5ad-a72e-435f-b7fc-68253a9dd980","name":"(State of Wakanda) Can this problem be solved with recursion ?","slug":"state-of-wakanda-can-this-problem-be-solved-with-recursion","type":4},{"id":"c8c1fada-1fb7-4ff4-a7a6-6c31c6f91c5e","name":"(State of Wakanda) For what the outer loop should traverse ?","slug":"state-of-wakanda-for-what-the-outer-loop-should-traverse","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":"18ef05e6-7a41-480f-ad63-0dfe1c24eabd","name":"The State Of Wakanda - 1","slug":"the-state-of-wakanda-1","type":1}],"next":{"id":"d12f6857-1963-4fd6-af7b-e28a5f8e659c","name":"The State Of Wakanda -1","type":3,"slug":"the-state-of-wakanda-1"},"prev":{"id":"beea55a6-71b3-4ace-a46e-32baca36383f","name":"Matrix Multiplication","type":3,"slug":"matrix-multiplication"}}}`

Editor

Loading...

# The State Of Wakanda - 1

easy

The historic state of Wakanda has various monuments and souvenirs which are visited by many travelers every day. The guides follow a prescribed route of visiting the monuments which improve them understand the relevance of each monument. The route of the monument is fixed and expressed in a 2-d matrix where the travelers visit the prescribed next monument. For example 1 2 3 4 5 6 7 8 9 is the prescribed route and the visitors travels this path: 1->2->3->4->5->6->7->8->9 However, a certain visitor decides to travel a different path as follows: 1. He first travels southwards till no further south places are available. 2. He then moves only 1 place eastwards. 3. He starts to move again towards north till any further north moves are available. This continues till all the places are covered. For example, the monuments are named as follows: 1 2 3 4 5 6 7 8 9 Path followed by traveler: 1->4->7->8->5->2->3->6->9 You are required to print the path that this traveler follows to visit all places. 1. You will be given a number n, representing the number of rows. 2. You will be given a number m, representing the number of columns. 3. You will be given n*m numbers, representing elements of 2d arrays. Note - Please check the output format for details.

## Constraints

1 <= n <= 10^2 1 <= m <= 10^2 -10^9 <= e1, e2, .. n * m elements <= 10^9

## Format

### Input

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

### Output

e11 e12 e13 .. e1n e2n e2n-1 .. e21 e31 e32 .. e3n e4n ..

## 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;}3 4 11 12 13 14 21 22 23 24 31 32 33 34```

### 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;}11 21 31 32 22 12 13 23 33 34 24 14```

Question Video

Discussions

Show Discussion

Related Resources