15% off all plans & roadmaps Use code
See plansLeetCode 867 · Solution & editorial
Given a 2D integer array matrix, return the transpose of matrix.
Transpose Matrix is a Array/Matrix Manipulation Patterns problem, in the In-place Rotation subpattern. The pattern covers in-place operations, hashing, prefix sums, spiral traversal, and cyclic sort
Learn in-place rotation techniques for arrays and matrices. Rotate without using extra space.
The reference solution runs in O(r * c) time and O(1) space.
Transpose Matrix has been reported in interviews at Apple, Microsoft, Nvidia, Citadel.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Transpose Matrix is a Array/Matrix Manipulation Patterns problem, in the In-place Rotation subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.