Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Rotate a matrix 90 degrees clockwise

Hardware interview practice

Rotate a matrix 90 degrees clockwise

MediumMatricesSystemVerilog

Rotate an N x N matrix 90 degrees clockwise 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
[[3, 1], [4, 2]]

Transposing and then reversing each row produces a 90-degree clockwise rotation.

What to cover

Requirements

  1. Assume the input has N rows and every row has exactly N elements.
  2. Use O(1) extra space.
  3. Do not allocate a second matrix.
  4. Preserve every element exactly once.
asic.fyi · Learn silicon end to end.info@asic.fyi