5 views
# Transpose Matrix (LeetCode 867) — Interview Notes `result[j][i] = matrix[i][j]` with shape n x m → m x n. Watch out for rectangular (not square) inputs — allocate new matrix. ```text m,n = len(matrix), len(matrix[0]) ans = [[0]*m for _ in range(n)] for i in range(m): for j in range(n): ans[j][i] = matrix[i][j] ``` Follow-up: in-place only for square. Notes drafted via [https://www.linkjob.ai/coding-interview-copilot/](https://www.linkjob.ai/coding-interview-copilot/).