10. Transpose of Matrix
Last updated
Was this helpful?
Last updated
Was this helpful?
The problem can be found at the following link:
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]
with mat[j][i]
.
Time Complexity: O(n^2)
since a nested loops run for n iterations, where n
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.
For discussions, questions, or doubts related to this solution, please visit our . 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 repository.