62. Transpose a Matrix
Core1000 ms256 MBSolved by 0%
Read a matrix with r rows and c columns, then print its transpose —
the matrix with rows and columns exchanged.
The transpose has c rows and r columns, and the value at row i, column j of the
result is the value at row j, column i of the input.
Print each row on its own line with values separated by single spaces.
Constraints - `1 ≤ r, c ≤ 100` - `-1000000 ≤ each value ≤ 1000000`
Input
The first line contains two integers r and c.
Each of the next r lines contains c space-separated integers.
Output
Print c lines of r integers each, separated by single spaces — the transposed grid.
Input2 3
1 2 3
4 5 6
Output1 4
2 5
3 6
Noteis a wide matrix that becomes tall
Input3 2
1 2
3 4
5 6
Output1 3 5
2 4 6
Noteis a tall matrix that becomes wide
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution