Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed Dec 5, 2023
1 parent c7175eb commit 4991065
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions coding_interviews/algoexpert/transpose-matrix/transpose-matrix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Runtime: O(R * C), R = rows and C = columns
// Space: O(N)

function transposeMatrix(matrix) {
let transposedMatrix = [];

for (let col = 0; col < matrix[0].length; col++) {
let newRow = [];
for (let row = 0; row < matrix.length; row++) {
let cell = matrix[row][col];
newRow.push(cell);
}
transposedMatrix.push(newRow);
}

return transposedMatrix;
}

0 comments on commit 4991065

Please sign in to comment.