Hardware interview practice
Transpose a rectangular matrix
Return the transpose of an R x C integer matrix as a new C x R matrix.
Reviewed example
Work through one case
Input
matrix = [[1, 2, 3], [4, 5, 6]]Expected output
[[1, 4], [2, 5], [3, 6]]Rows become columns, so a 2x3 input produces a 3x2 output.
What to cover
Requirements
- Return an empty matrix for an empty input.
- Assume every input row has the same number of columns.
- Allocate every output row to the original row count.
- Assign out[c][r] from input[r][c].
