A seismograph array logs an R-by-C grid of integer amplitude readings: R rows (sensors), each with C timed readings. To realign the log by time instead of by sensor, output the transpose of the grid: a C-by-R grid whose entry in row j, column i equals the original entry in row i, column j.
Line 1: two integers R and C.
Next R lines: each contains C space-separated integers (one grid row).
C lines, each with R space-separated integers: the transposed grid.
Example 1
Input
2 3 1 2 3 4 5 6
Expected
1 4 2 5 3 6
Explanation
The 2x3 grid becomes a 3x2 grid: column 0 (1,4) becomes row 0, column 1 (2,5) becomes row 1, column 2 (3,6) becomes row 2.
Example 2
Input
1 1 7
Expected
7
Explanation
A single-cell grid is its own transpose.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →