Transpose the Matrix
EasyP3Coding
Return the transpose of an n x m matrix: an m x n matrix whose entry at row j, column i is matrix[i][j]. Rows become columns.
Example 1
- Input
- matrix = [[1,2,3],[4,5,6]]
- Output
- [[1,4],[2,5],[3,6]]
Example 2
- Input
- matrix = [[1,2],[3,4]]
- Output
- [[1,3],[2,4]]
Example 3
- Input
- matrix = [[5]]
- Output
- [[5]]
Constraints
- 1 <= n, m <= 100
- -10^9 <= matrix[i][j] <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.