`{"id":"61bbc4ec-64fc-4396-a4c3-c2ca65cc187f","name":"Transpose Of Matrix With Dimension M X N","description":"1. You have a matrix of M*N Dimension.\r\n2. You have to return a Transpose matrix, where The transpose of a matrix is the matrix flipped over its main diagonal.\r\n","inputFormat":"matrix = {\r\n {11, 12, 13},\r\n {21, 22, 23}\r\n}","outputFormat":"res = {\r\n {11, 21},\r\n {12, 22},\r\n {13, 23}\r\n}","constraints":"1. m == matrix.length\r\n2. n == matrix[i].length\r\n3. 1 &lt;= m, n &lt;= 1000\r\n4. 1 &lt;= m * n &lt;= 10^5\r\n5. -10^9 &lt;= matrix[i][j] &lt;= 10^9\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\n\n\n // ~~~~~~~~~~~~~User Section~~~~~~~~~~~~~\n vector<vector<int>> transpose(vector<vector<int>> matrix) {\n // write your code here\n \n \n }\n\n\n // ~~~~~~~~~~~Input Management~~~~~~~~~~~\n int main() {\n int n;\n int m;\n cin>>n;\n cin>>m;\n vector<vector<int>> matrix (n,vector<int>(m));\n\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n cin>>matrix[i][j];\n }\n }\n\n vector<vector<int>> res = transpose(matrix);\n\n for (int i = 0; i < res.size(); i++) {\n for (int j = 0; j < res[0].size(); j++) {\n cout<<res[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 int[][] transpose(int[][] matrix) {\r\n // write your code here\r\n }\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 m = scn.nextInt();\r\n\r\n int[][] matrix = new int[n][m];\r\n\r\n for (int i = 0; i < n; i++) {\r\n for (int j = 0; j < m; j++) {\r\n matrix[i][j] = scn.nextInt();\r\n }\r\n }\r\n\r\n int[][] res = transpose(matrix);\r\n\r\n for (int i = 0; i < res.length; i++) {\r\n for (int j = 0; j < res[0].length; j++) {\r\n System.out.print(res[i][j] + \" \");\r\n }\r\n System.out.println();\r\n }\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"2 3\r\n11 12 13\r\n21 22 23","sampleOutput":"11 21 \r\n12 22 \r\n13 23 ","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":"fa27c59c-543b-4419-8c23-42e6a1fb4515","name":"Transpose Of Matrix With Dimension M X N","slug":"transpose-of-matrix-with-dimension-m-x-n","type":1}],"next":{"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"},"prev":{"id":"c1140024-33de-4bdf-881b-a9f79b93b005","name":"Number Of Subarrays With Bounded Maximum","type":3,"slug":"number-of-subarrays-with-bounded-maximum"}}}`

# Transpose Of Matrix With Dimension M X N

1. You have a matrix of M*N Dimension. 2. You have to return a Transpose matrix, where The transpose of a matrix is the matrix flipped over its main diagonal.

`{"id":"61bbc4ec-64fc-4396-a4c3-c2ca65cc187f","name":"Transpose Of Matrix With Dimension M X N","description":"1. You have a matrix of M*N Dimension.\r\n2. You have to return a Transpose matrix, where The transpose of a matrix is the matrix flipped over its main diagonal.\r\n","inputFormat":"matrix = {\r\n {11, 12, 13},\r\n {21, 22, 23}\r\n}","outputFormat":"res = {\r\n {11, 21},\r\n {12, 22},\r\n {13, 23}\r\n}","constraints":"1. m == matrix.length\r\n2. n == matrix[i].length\r\n3. 1 &lt;= m, n &lt;= 1000\r\n4. 1 &lt;= m * n &lt;= 10^5\r\n5. -10^9 &lt;= matrix[i][j] &lt;= 10^9\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\n\n\n // ~~~~~~~~~~~~~User Section~~~~~~~~~~~~~\n vector<vector<int>> transpose(vector<vector<int>> matrix) {\n // write your code here\n \n \n }\n\n\n // ~~~~~~~~~~~Input Management~~~~~~~~~~~\n int main() {\n int n;\n int m;\n cin>>n;\n cin>>m;\n vector<vector<int>> matrix (n,vector<int>(m));\n\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n cin>>matrix[i][j];\n }\n }\n\n vector<vector<int>> res = transpose(matrix);\n\n for (int i = 0; i < res.size(); i++) {\n for (int j = 0; j < res[0].size(); j++) {\n cout<<res[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 int[][] transpose(int[][] matrix) {\r\n // write your code here\r\n }\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 m = scn.nextInt();\r\n\r\n int[][] matrix = new int[n][m];\r\n\r\n for (int i = 0; i < n; i++) {\r\n for (int j = 0; j < m; j++) {\r\n matrix[i][j] = scn.nextInt();\r\n }\r\n }\r\n\r\n int[][] res = transpose(matrix);\r\n\r\n for (int i = 0; i < res.length; i++) {\r\n for (int j = 0; j < res[0].length; j++) {\r\n System.out.print(res[i][j] + \" \");\r\n }\r\n System.out.println();\r\n }\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"2 3\r\n11 12 13\r\n21 22 23","sampleOutput":"11 21 \r\n12 22 \r\n13 23 ","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":"fa27c59c-543b-4419-8c23-42e6a1fb4515","name":"Transpose Of Matrix With Dimension M X N","slug":"transpose-of-matrix-with-dimension-m-x-n","type":1}],"next":{"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"},"prev":{"id":"c1140024-33de-4bdf-881b-a9f79b93b005","name":"Number Of Subarrays With Bounded Maximum","type":3,"slug":"number-of-subarrays-with-bounded-maximum"}}}`

Editor

# Transpose Of Matrix With Dimension M X N

easy

1. You have a matrix of M*N Dimension. 2. You have to return a Transpose matrix, where The transpose of a matrix is the matrix flipped over its main diagonal.

## Constraints

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

## Format

### Input

matrix = { {11, 12, 13}, {21, 22, 23} }

### Output

res = { {11, 21}, {12, 22}, {13, 23} }

## 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;}2 3 11 12 13 21 22 23```

### 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 12 22 13 23 ```

Discussions

Show Discussion

Related Resources