-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay_19.py
More file actions
28 lines (19 loc) · 718 Bytes
/
Day_19.py
File metadata and controls
28 lines (19 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
DAY 19 : Transpose of Matrix.
https://www.geeksforgeeks.org/program-to-find-transpose-of-a-matrix/
QUESTION : Write a program to find the transpose of a square matrix of size N*N.
Transpose of a matrix is obtained by changing rows to columns and columns to rows.
Expected Time Complexity: O(N * N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 100
-10^3 <= mat[i][j] <= 10^3
"""
def transpose(matrix):
for i in range(len(matrix)):
for j in range(len(matrix)):
if i<j:
matrix[i][j] ,matrix[j][i] = matrix[j][i], matrix[i][j]
print(matrix)
matrix = [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]
transpose(matrix)