Hardware interview practice
Rotate a matrix 90 degrees clockwise
Rotate an N x N matrix 90 degrees clockwise in place.
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
- 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.
