Medium

Quiz

#59 Spiral Matrix II

APPROACH

Construct and return an n x n matrix whose entries are integers 1 through n2 placed in clockwise spiral order.

Example 1:

Input: n = 3
Output: [[1,2,3],[8,9,4],[7,6,5]]

Example 2:

Input: n = 1
Output: [[1]]
1 of 4
1:00

What is the optimal approach for this problem?