10. Transpose of Matrix
The problem can be found at the following link: Question Link
My Approach
The problem of transposing a matrix can be solved by using two index variables, i and j. We can iterate over i
from 0 to n - 1
and j
from i to n - 1
to avoid unnecessary repetition.
In each iteration, we swap the elements
mat[i][j]
withmat[j][i]
.
Time and Auxiliary Space Complexity
Time Complexity:
O(n^2)
since a nested loops run for n iterations, wheren
is the size of the matrix.Auxiliary Space Complexity:
O(1)
since these operations were performed in-place, meaning it does not require any additional space.
Code (C++)
Contribution and Support
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star to the getlost01/gfg-potd repository.
Last updated