DescriptionQ895
Q895FWASIC interview problem
Transpose a rectangular matrix
TechniquesMatrixDynamic arrays
DifficultyEasy
TopicMatrices
LanguageSystemVerilog
Requirements4 checkpoints
01
Problem
Return the transpose of an R x C integer matrix as a new C x R matrix.
Example input and output
Use this case to check your interpretationInput
matrix = [[1, 2, 3], [4, 5, 6]]Output
[[1, 4], [2, 5], [3, 6]]Explanation
Rows become columns, so a 2x3 input produces a 3x2 output.
02
Requirements (4)
- 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].
