Spiral Matrix II
Given a positive integer n, generate an n x n matrix filled with the elements from 1 to n^2 placed in clockwise spiral order starting at the top-left corner.
Open official problem prompt ↗Produce the n x n grid whose cells hold 1..n^2 laid down along a clockwise inward spiral.
Like coiling a rope neatly into a square bin, laying each successive foot of rope next to the last as you wind inward.
- Input
- n = 3
- Output
- [[1,2,3],[8,9,4],[7,6,5]]
- Why
- Writing 1..9 clockwise from the top-left fills the outer ring 1..8 and leaves 9 in the center.
1 <= n <= 20