DescriptionQ021
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 interpretationInput
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.
