Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ021
Page ↗
Q021FWASIC interview problem

Rotate a matrix 90 degrees clockwise

TechniquesMatrixIn place
DifficultyMedium
TopicMatrices
LanguageSystemVerilog
Requirements4 checkpoints
01

Problem

Rotate an N x N matrix 90 degrees clockwise in place.

Example input and output

Use this case to check your interpretation
Input
matrix = [[1, 2], [3, 4]]
Output
[[3, 1], [4, 2]]
Explanation

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

02

Requirements (4)

  • Assume the input has N rows and every row has exactly N elements.
  • Use O(1) extra space.
  • Do not allocate a second matrix.
  • Preserve every element exactly once.