forked from dsrao711/DSA-Together-HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SnakePattern.py
43 lines (36 loc) · 966 Bytes
/
SnakePattern.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def snakePattern(matrix):
# code here
n_rows = len(matrix)
n_columns = len(matrix[0])
k = 0
output = []
left_spiral=[]
for i in range(0 , n_rows):
if(i%2 == 0):
for j in range(0 , n_columns):
output.append(matrix[i][j])
elif(i%2 != 0):
for j in range(n_columns-1 , -1, -1):
output.append(matrix[i][j])
return output
#{
# Driver Code Starts
#Initial Template for Python 3
if __name__ == '__main__':
t = int(input())
for _ in range(t):
n = int(input())
values = list(map(int, input().strip().split()))
k = 0
matrix =[]
for i in range(n):
row=[]
for j in range(n):
row.append(values[k])
k+=1
matrix.append(row)
ans = snakePattern(matrix)
for i in ans:
print(i,end=" ")
print()
# } Driver Code Ends