File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+
3
+ #https://practice.geeksforgeeks.org/problems/rotate-by-90-degree0356/1/?company[]=Morgan%20Stanley&company[]=Morgan%20Stanley&page=1&query=company[]Morgan%20Stanleypage1company[]Morgan%20Stanley
4
+
5
+
6
+ def rotate (a ):
7
+ #code here
8
+
9
+ n = len (a )
10
+
11
+ # Transpose
12
+ for i in range (n ):
13
+ for j in range (i ):
14
+ a [i ][j ] , a [j ][i ] = a [j ][i ] , a [i ][j ]
15
+
16
+ # Rotate the rows
17
+
18
+ for i in range (int (n / 2 )):
19
+ a [i ] , a [n - i - 1 ] = a [n - i - 1 ] , a [i ]
20
+
21
+ return a
22
+
23
+ #{
24
+ # Driver Code Starts
25
+ #Initial Template for Python 3
26
+
27
+
28
+ if __name__ == '__main__' :
29
+ t = int (input ())
30
+ for _ in range (t ):
31
+ N = int (input ())
32
+ arr = [int (x ) for x in input ().split ()]
33
+ matrix = []
34
+
35
+ for i in range (0 ,N * N ,N ):
36
+ matrix .append (arr [i :i + N ])
37
+
38
+ rotate (matrix )
39
+ for i in range (N ):
40
+ for j in range (N ):
41
+ print (matrix [i ][j ], end = ' ' )
42
+ print ()
43
+
44
+
45
+ # } Driver Code Ends
You can’t perform that action at this time.
0 commit comments