BETA
Spirally traversing a matrix
Submissions: 16852   Accuracy:

35.07%

  Difficulty: Easy

Given a m*n matrix, traverse the matrix in spiral form.

Input:
The first line of the input contains a single integer T, denoting the number of test cases. Then T test cases follow. Each testcase has 2 lines
m and n separated by a space
The mxn values separated by spaces

Output:
Spiral array will be displayed in a single line.

Constraints:
1 <=T<= 100
2<=m,n<=10
0<=A[i]<=100

Example:
Input:
1
4 4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Output:
1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10

** For More Input/Output Examples Use 'Expected Output' option **

Author: atharv


Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.