Given a 2d array or a matrix. write an efficient algorithm to print this 2d array in spiral form.

**Example **

Suppose following nodes are inserted on Given Array.

Result: print this array in spiral form

Output : [1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 17 18 19 20 21 22 23 24 25 26 27 28 30 31 32 33 34 35 ].

Another example:

Spiral Form presentation.

Output : 1 2 3 4 5 7 8 9 10 11 12 13 14 15 16 17 18 19 32 33 24 25 26 27 28 29 30 31 34 35

Program for Print matrix in spiral from in c. iterative Solution time complexity O(n).

**Output**

Array data presentation.

Visualize process Try it Yourself

Submit your solution in comment.

View comments and participate Discussion