Tell me, what's problem in this code ? it show me error for 21 input. even my code return value and expected value is same


#1

int n=A,k=1;
int t=0,b=n-1,r=n-1,l=0;
int arr[][]=new int[n][n];
if(n==1)
{
arr[0][0]=1;
return arr;
}

    while(t<b && l<r)
    {
        for(int i=l;i<=r;i++)
        {
            arr[t][i]=k;
            k++;
        }
        t++;
        
        for(int i=t;i<=b;i++)
        {
            arr[i][r]=k;
            k++;
        }
        r--;
        for(int i=r;i>=l;i--)
        {
            arr[b][i]=k;
            k++;
        }
        b--;
        
        for(int i=b;i>=t;i--)
        {
            arr[i][l]=k;
            k++;
        }
        l++;
    }
    return arr;

#2

For while condition put t <= b and similarly l <= r