<p>Given a positive integer <code>n</code>, generate an <code>n x n</code> <code>matrix</code> filled with elements from <code>1</code> to <code>n<sup>2</sup></code> in spiral order.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/spiraln.jpg" style="width: 242px; height: 242px;" />
<pre>
<strong>Input:</strong> n = 3
<strong>Output:</strong> [[1,2,3],[8,9,4],[7,6,5]]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 1
<strong>Output:</strong> [[1]]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 20</code></li>
</ul>

class Solution:
    def generateMatrix(self, n: int) -> List[List[int]]:
        
        tr = 0 
        br = n-1

        lc = 0
        rc = n-1

        matrix = [[-1 for i in range(n)]for j in range (n)]
        nums_to_fill = [x for x in range(1,n**2+1)]
        count = 0
        while tr <= br and lc <= rc:
            for i in range(lc,rc+1): # fill left to right
                matrix[tr][i]= nums_to_fill[count]
                count+=1
            tr +=1

            for j in range (tr,br+1): # fill top to down
                matrix[j][rc] = nums_to_fill[count]
                count +=1 
            rc -= 1

            for i in range(rc,lc-1,-1):
                matrix[br][i]= nums_to_fill[count]
                count+=1 
            br -=1
            for j in range(br,tr-1,-1):
                matrix[j][lc]= nums_to_fill[count]
                count+=1
            lc +=1
        return matrix
            



16600