Given a matrix mat[][] of size N x N. The task is to print the elements of the matrix in the snake pattern.
Input:
First line consists of an integer T denoting the number of test cases. First line of each test case consists of N, denoting number of elements(N x N) in Matrix. Second line of every test case consists of N x N spaced integers denoting elements of Matrix elements.
Output:
For each testcase, in a new line, print the matrix in snake pattern.
Constraints:
1 <= T <= 100
1 <= N <= 100
1 <= mat[i][j] <= 100
Example:
Input:
2
3
45 48 54 21 89 87 70 78 15
2
25 27 23 21
Output:
45 48 54 87 89 21 70 78 15
25 27 21 23
Explanation:
Testcase 1: Matrix is as below:
45 48 54
21 89 87
70 78 15
Printing it in snake pattern will lead to the output as 45 48 54 87 89 21 70 78 15.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.
bruceewayne | 193 |
manvirag982 | 182 |
Core_Ka_Bachha | 180 |
shivam123ahuja | 175 |
Sanjana Singh 1 | 173 |
mr_kksparrow | 433 |
manvirag982 | 398 |
TheHandle | 291 |
rajupraaa1234 | 276 |
Exception_404 | 268 |
blackshadows | 5331 |
Ibrahim Nash | 5219 |
akhayrutdinov | 5111 |
mb1973 | 4929 |
Quandray | 4567 |