Transpose of Matrix | GeeksforGeeks‬ Beginner’s DSA Sheet | Full Solution Explained | With Source Code

hola coders!

In this video, I directly solve a problem on the transpose of a matrix—no unnecessary theory, just straight to the point 🙂

Problem Link: https://www.geeksforgeeks.org/problems/transpose-of-matrix-1587115621/1

Source C…


This content originally appeared on DEV Community and was authored by Debesh P.

hola coders!

In this video, I directly solve a problem on the transpose of a matrix—no unnecessary theory, just straight to the point :)

Problem Link: https://www.geeksforgeeks.org/problems/transpose-of-matrix-1587115621/1

Source Code: https://github.com/debeshp6/Gfg-Tutorials/blob/main/TransposeOfMatrix.java

Code

class Solution {
    public void transpose(int n, int mat[][]) {

        // mat[][] is a 2D array here
        // n is the array length
        // let's start!

        for(int i=0; i<n; i++) { // first iteration
            for(int j=i+1; j<n; j++) { // second iteration
                int temp = mat[i][j]; // here we are simply swapping the values using a third 'temp' variable
                mat[i][j] = mat[j][i];
                mat[j][i] = temp;
            }
        }
    }
}

Time Complexity: O(n^2)

Have questions or doubts? Drop them in the comments, and I'll be happy to help!


This content originally appeared on DEV Community and was authored by Debesh P.


Print Share Comment Cite Upload Translate Updates
APA

Debesh P. | Sciencx (2025-04-02T06:22:03+00:00) Transpose of Matrix | GeeksforGeeks‬ Beginner’s DSA Sheet | Full Solution Explained | With Source Code. Retrieved from https://www.scien.cx/2025/04/02/transpose-of-matrix-geeksforgeeks-beginners-dsa-sheet-full-solution-explained-with-source-code/

MLA
" » Transpose of Matrix | GeeksforGeeks‬ Beginner’s DSA Sheet | Full Solution Explained | With Source Code." Debesh P. | Sciencx - Wednesday April 2, 2025, https://www.scien.cx/2025/04/02/transpose-of-matrix-geeksforgeeks-beginners-dsa-sheet-full-solution-explained-with-source-code/
HARVARD
Debesh P. | Sciencx Wednesday April 2, 2025 » Transpose of Matrix | GeeksforGeeks‬ Beginner’s DSA Sheet | Full Solution Explained | With Source Code., viewed ,<https://www.scien.cx/2025/04/02/transpose-of-matrix-geeksforgeeks-beginners-dsa-sheet-full-solution-explained-with-source-code/>
VANCOUVER
Debesh P. | Sciencx - » Transpose of Matrix | GeeksforGeeks‬ Beginner’s DSA Sheet | Full Solution Explained | With Source Code. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/04/02/transpose-of-matrix-geeksforgeeks-beginners-dsa-sheet-full-solution-explained-with-source-code/
CHICAGO
" » Transpose of Matrix | GeeksforGeeks‬ Beginner’s DSA Sheet | Full Solution Explained | With Source Code." Debesh P. | Sciencx - Accessed . https://www.scien.cx/2025/04/02/transpose-of-matrix-geeksforgeeks-beginners-dsa-sheet-full-solution-explained-with-source-code/
IEEE
" » Transpose of Matrix | GeeksforGeeks‬ Beginner’s DSA Sheet | Full Solution Explained | With Source Code." Debesh P. | Sciencx [Online]. Available: https://www.scien.cx/2025/04/02/transpose-of-matrix-geeksforgeeks-beginners-dsa-sheet-full-solution-explained-with-source-code/. [Accessed: ]
rf:citation
» Transpose of Matrix | GeeksforGeeks‬ Beginner’s DSA Sheet | Full Solution Explained | With Source Code | Debesh P. | Sciencx | https://www.scien.cx/2025/04/02/transpose-of-matrix-geeksforgeeks-beginners-dsa-sheet-full-solution-explained-with-source-code/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.