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.

  1. Create a new, empty 2D structure.
  2. Map every element such that its new position is Result[col][row].
  3. 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]]
Output1 3 2 4

Explanation: Rows [1,2], [3,4] become [1,3], [2,4].

Constraints

  • Correct Row/Col count for non-square matrices.
ArraysMatrix
JavaScript
Loading...
1 Hidden

Input Arguments

grid[[1,2],[3,4]]

Expected Output

1 3
2 4

Click RUN to test your solution