
Transpose Matrix (easy)
Problem Statement
Given a 2D array matrix, return the transpose of the matrix.
In the transpose matrix, the first row of the original matrix becomes the first column, the second row becomes the second column, and so on.
Examples
- Example 1:
- Input:
[[1,2],
[3,4]]
- Expected Output:
[[1,3],
[2,4]]
-
Justification: The first row
[1,2]becomes the first column[1,3], and the second row[3,4]becomes the second column[2,4]. -
Example 2:
- Input:
[[5,6,7],
[8,9,10],
[11,12,13]]
- Expected Output:
[[5,8,11],
[6,9,12],
[7,10,13]]
-
Justification: The matrix is rearranged such that each row becomes a column in the transposed matrix.
-
Example 3:
- Input:
[[14,15,16,17],
[18,19,20,21],
[22,23,24,25],
[26,27,28,29]]
- Expected Output:
[[14,18,22,26],
[15,19,23,27],
[16,20,24,28],
[17,21,25,29]]
- Justification: Similar to the previous examples, each row of the original matrix is transformed into a column in the transposed matrix.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory