Transpose Matrix
MediumAcc. 94.1%
+25 XP 10
The Dimension Flip (Transpose)
Transposing a matrix is like flipping a square over its main diagonal. The rows of the original grid become the columns of the new one. This operation is the backbone of many mathematical algorithms and data transformations.
The Assignment
Your mission is to flip the dimensions of the grid. Your function receives grid.
- Create a new, empty 2D structure.
- Map every element such that its new position is
Result[col][row]. - Print the resulting matrix row by row. Each element in a row should be separated by a space.
01EXAMPLE 1
Input
[[1, 2], [3, 4]]Output
1 3
2 4Explanation: Rows [1,2], [3,4] become [1,3], [2,4].
Constraints
- Correct Row/Col count for non-square matrices.
ArraysMatrix
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
grid[[1,2],[3,4]]
Expected Output
1 3 2 4
Click RUN to test your solution