<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]]:
        li=[[0]*n for i in range(n)]
        l=0
        r=n-1
        t=0
        b=n-1
        val=1
        while t<=b and l<=r:
            for i in range(l,r+1):
                li[t][i]=val
                val=val+1
            t+=1
            for i in range(t,b+1):
                li[i][r]=val
                val=val+1
            r=r-1
            if t<=b:
                for i in range(r,l-1,-1):
                    li[b][i]=val
                    val=val+1
                b=b-1
            if l<=r:
                for i in range(b,t-1,-1):
                    li[i][l]=val
                    val=val+1
                l+=1
        ll=[]
        for i in li:
            ll.append(i)
        return ll
        
16500