Wrong answer for n=58. Can anybody help please


#1

The code runs fine in my IDE but showing wrong answer here.
Here is my code

int it;
vector<vector<int>> ve;
void traverse(int sr, int sc, int er, int ec){
    for(int i=sc;i<=ec;i++){
        ve[sr][i]=it++;
    }
    sr++;
    for(int i=sr;i<=er;i++){
        ve[i][ec]=it++;
    }
    ec--;
    for(int i=ec;i>=sc;i--){
        ve[er][i]=it++;
    }
    er--;
    for(int i=er;i>=sr;i--){
        ve[i][sc]=it++;
    }
    
}

vector<vector<int> > Solution::generateMatrix(int A) {
    it=1;
    vector<int> te;
    for(int i=0;i<A;i++){
        te.clear();
        for(int j=0;j<A;j++)te.push_back(0);
        ve.push_back(te);
    }
    int sr=0,sc=0,er=A-1,ec=A-1;
    for(int i=0;i<A;i++){
        if(sr>er || sc > ec)break;
        traverse(sr,sc,er,ec);
        sr++;er--;sc++;ec--;
    }
    return ve;
}