Spiral Matrix

4

1 votes
Problem

 

Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order.

Input:

First line -Read N integer

Output:

n*n matrix in required format

Explanation

N=3

Matrix=

[[1   2   3],[8   9   4],[7   6   5]]

Sample Input
2
Sample Output
[[1,2],[4,3]]
Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?