Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Transpose a square matrix in place

Hardware interview practice

Transpose a square matrix in place

EasyMatricesSystemVerilog

Transpose an N x N matrix in place.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Reviewed example

Work through one case

Input
matrix = [[1, 2], [3, 4]]
Expected output
[[1, 3], [2, 4]]

Swapping the off-diagonal pair performs the square transpose in place.

What to cover

Requirements

  1. Assume the input has N rows and every row has exactly N elements.
  2. Swap only one side of the diagonal.
  3. Leave diagonal elements unchanged.
  4. Use O(1) extra space.
asic.fyi · Learn silicon end to end.info@asic.fyi