{"id":"bb534507-05f5-48cf-a7ec-e439e7009ea8","name":"Transpose Of Matrix With Dimension N X N","description":"1. You have a matrix of N*N Dimension.\r\n2. You have to convert matrix into transpose.\r\n3. Transpose matrix is defined as, matrix flipped over its main diagonal.\r\n","inputFormat":"matrix = {\r\n {11, 12, 13},\r\n {21, 22, 23},\r\n {31, 32, 33}\r\n}","outputFormat":"res = {\r\n {11, 21, 31},\r\n {12, 22, 32},\r\n {13, 23, 33}\r\n}","constraints":"1. n == matrix.length\r\n2. 1 &lt;= n &lt;= 1000\r\n3. 1 &lt;= n * n &lt;= 10^5\r\n4. -10^9 &lt;= matrix[i][j] &lt;= 10^9\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nvoid transpose(vector<vector<int>> & arr){\n //Write your code here\n \n}\n\nint main(){\n int n;\n cin>>n;\n vector<vector<int>> arr(n, vector<int>(n,0));\n for(int i=0; i<n; i++){\n for(int j=0; j<n; j++){\n cin>>arr[i][j];\n }\n }\n transpose(arr);\n for(int i=0; i<n; i++){\n for(int j=0; j<n; j++){\n cout<<arr[i][j]<<\" \";\n }\n cout<<endl;\n }\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n // ~~~~~~~~~~~~~User Section~~~~~~~~~~~~~\r\n public static void transpose(int[][] matrix) {\r\n // write your code here\r\n }\r\n\r\n // ~~~~~~~~~~~Input Management~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[][] matrix = new int[n][n];\r\n for (int i = 0; i < n; i++) {\r\n for (int j = 0; j < n; j++) {\r\n matrix[i][j] = scn.nextInt();\r\n }\r\n }\r\n transpose(matrix);\r\n for (int i = 0; i < n; i++) {\r\n for (int j = 0; j < n; j++) {\r\n System.out.print(matrix[i][j] + \" \");\r\n }\r\n System.out.println();\r\n }\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"3\r\n11 12 13\r\n21 22 23\r\n31 32 33","sampleOutput":"11 21 31 \r\n12 22 32 \r\n13 23 33 ","questionVideo":"","hints":[],"associated":[],"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":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"ca9f0571-791e-4238-bf74-7dcf9b684f0e","name":"Transpose Of Matrix With Dimension N X N","slug":"transpose-of-matrix-with-dimension-n-x-n","type":1}],"next":{"id":"69fe509b-127b-431b-9342-c213061f7404","name":"Transpose Of Matrix With Dimension N X N","type":3,"slug":"transpose-of-matrix-with-dimension-n-x-n"},"prev":{"id":"df271d56-98e2-429a-ab3d-e42149d8913c","name":"Transpose Of Matrix With Dimension M X N","type":3,"slug":"transpose-of-matrix-with-dimension-m-x-n"}}}

Transpose Of Matrix With Dimension N X N

1. You have a matrix of N*N Dimension. 2. You have to convert matrix into transpose. 3. Transpose matrix is defined as, matrix flipped over its main diagonal.

{"id":"bb534507-05f5-48cf-a7ec-e439e7009ea8","name":"Transpose Of Matrix With Dimension N X N","description":"1. You have a matrix of N*N Dimension.\r\n2. You have to convert matrix into transpose.\r\n3. Transpose matrix is defined as, matrix flipped over its main diagonal.\r\n","inputFormat":"matrix = {\r\n {11, 12, 13},\r\n {21, 22, 23},\r\n {31, 32, 33}\r\n}","outputFormat":"res = {\r\n {11, 21, 31},\r\n {12, 22, 32},\r\n {13, 23, 33}\r\n}","constraints":"1. n == matrix.length\r\n2. 1 &lt;= n &lt;= 1000\r\n3. 1 &lt;= n * n &lt;= 10^5\r\n4. -10^9 &lt;= matrix[i][j] &lt;= 10^9\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nvoid transpose(vector<vector<int>> & arr){\n //Write your code here\n \n}\n\nint main(){\n int n;\n cin>>n;\n vector<vector<int>> arr(n, vector<int>(n,0));\n for(int i=0; i<n; i++){\n for(int j=0; j<n; j++){\n cin>>arr[i][j];\n }\n }\n transpose(arr);\n for(int i=0; i<n; i++){\n for(int j=0; j<n; j++){\n cout<<arr[i][j]<<\" \";\n }\n cout<<endl;\n }\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n // ~~~~~~~~~~~~~User Section~~~~~~~~~~~~~\r\n public static void transpose(int[][] matrix) {\r\n // write your code here\r\n }\r\n\r\n // ~~~~~~~~~~~Input Management~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[][] matrix = new int[n][n];\r\n for (int i = 0; i < n; i++) {\r\n for (int j = 0; j < n; j++) {\r\n matrix[i][j] = scn.nextInt();\r\n }\r\n }\r\n transpose(matrix);\r\n for (int i = 0; i < n; i++) {\r\n for (int j = 0; j < n; j++) {\r\n System.out.print(matrix[i][j] + \" \");\r\n }\r\n System.out.println();\r\n }\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"3\r\n11 12 13\r\n21 22 23\r\n31 32 33","sampleOutput":"11 21 31 \r\n12 22 32 \r\n13 23 33 ","questionVideo":"","hints":[],"associated":[],"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":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"ca9f0571-791e-4238-bf74-7dcf9b684f0e","name":"Transpose Of Matrix With Dimension N X N","slug":"transpose-of-matrix-with-dimension-n-x-n","type":1}],"next":{"id":"69fe509b-127b-431b-9342-c213061f7404","name":"Transpose Of Matrix With Dimension N X N","type":3,"slug":"transpose-of-matrix-with-dimension-n-x-n"},"prev":{"id":"df271d56-98e2-429a-ab3d-e42149d8913c","name":"Transpose Of Matrix With Dimension M X N","type":3,"slug":"transpose-of-matrix-with-dimension-m-x-n"}}}
plane

Editor


Loading...

Transpose Of Matrix With Dimension N X N

easy

1. You have a matrix of N*N Dimension. 2. You have to convert matrix into transpose. 3. Transpose matrix is defined as, matrix flipped over its main diagonal.

Constraints

1. n == matrix.length 2. 1 <= n <= 1000 3. 1 <= n * n <= 10^5 4. -10^9 <= matrix[i][j] <= 10^9

Format

Input

matrix = { {11, 12, 13}, {21, 22, 23}, {31, 32, 33} }

Output

res = { {11, 21, 31}, {12, 22, 32}, {13, 23, 33} }

Example

Sample Input

3 11 12 13 21 22 23 31 32 33

Sample Output

11 21 31 12 22 32 13 23 33

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode