We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cf312a1 commit 6ca07d2Copy full SHA for 6ca07d2
867. Transpose Matrix
@@ -0,0 +1,26 @@
1
+//Followup qs. for interview
2
+
3
+### What if the input is always a square matrix?
4
+#### Code-
5
+ for(int i=0; i<n; i++){
6
+ for(int j=i+1; j<n; j++){
7
+ swap(matrix[i][j],matrix[j][i]);
8
+ }
9
10
11
+public:
12
13
+ vector<vector<int>> transpose(vector<vector<int>>& matrix) {
14
+ int m = matrix.size();
15
+ int n = matrix[0].size();
16
17
+ vector<vector<int>> result(n, vector<int>(m)); //n x m - T.c S.C - O(1)
18
19
+ for(int i=0; i<m; i++){
20
+ for(int j=0; j<n; j++){
21
+ result[j][i] = matrix[i][j];
22
23
24
+ return result;
25
26
+};
0 commit comments