Skip to content

Latest commit

 

History

History

challenge-1

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Spirally traversing a matrix

The original challenge description can be found here

Description

Given a 2D matrix of size M*N. Traverse and print the matrix in spiral form.

Input

  • Array of values
  • Dimension M (number of rows)
  • Dimension N (number of columns)

Output

Elements when travelled in Spiral form, will be displayed in a single line.

Constraints:

1 <=T<= 100

2 <= M, N <= 10

0 <= Ai <= 100

Example:

Input:
  Array: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
  M: 4
  N: 4

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