Given an integer n, generate an n x n matrix filled with the numbers 1 through n^2 in clockwise spiral order.
Start at the top-left corner, move right first, and keep turning clockwise whenever you would leave the current unfilled region.
Input / output
n: intint[][]Examples
n = 1 returns [[1]].n = 3 returns [[1,2,3],[8,9,4],[7,6,5]].n = 4 returns [[1,2,3,4],[12,13,14,5],[11,16,15,6],[10,9,8,7]].Constraints
1 <= n <= 20Follow-up Can you describe the loop invariant for the four shrinking boundaries, and why odd-sized matrices do not need a special center-case branch?