301. Spiral Matrix Generator
MediumSimulation
Print an n×n matrix filled with 1 … n² in clockwise spiral order.
Input format
A single integer n.
Output format
n lines of n integers.
Example 1
Input
3
Output
1 2 3 8 9 4 7 6 5
Example 2
Input
1
Output
1
Constraints
1 ≤ n ≤ 100
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…