Hardware interview practice
Transpose a square matrix in place
Transpose an N x N matrix in place.
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
- Assume the input has N rows and every row has exactly N elements.
- Swap only one side of the diagonal.
- Leave diagonal elements unchanged.
- Use O(1) extra space.
