Why am I getting wrong answer


#1

vector<vector > Solution::generateMatrix(int A) {
vector<vector > ans(A, vector(A));
vector<vector > arr(A, vector(A));

int i,j;
for(i=0;i<A;i++){
    for(j=0;j<A;j++){
        arr[i][j] = (i*A)+j+1;
    }
}

int start_row = 0;
int end_row = A-1;
int start_col = 0;
int end_col = A-1;

int dir=1;

int x=0,y=0;
while(start_row<end_row && start_col<end_col){
    
    if(dir==1){
        for(i=start_col; i<=end_col; i++){
            // cout<<x<<y<<dir<<endl;
            ans[x][y]=arr[start_row][i];
            y++;
            if(y==A){
                x++;
                y=0;
            }
            y=y%A;
            x=x%A;
        }
        start_row++;
        dir=2;
    }
    else if(dir==2){
        for(i=start_row; i<=end_row; i++){
            // cout<<x<<y<<dir<<endl;
            ans[x][y]=arr[i][end_col];
            y++;
            if(y==A){
                x++;
                y=0;
            }
            y=y%A;
            x=x%A;
        }
        end_col--;
        dir=3;
    }
    else if(dir==3){
        for(i=end_col; i>=start_col; i--){
            // cout<<x<<y<<dir<<endl;
            ans[x][y] = arr[end_row][i];
            y++;
            if(y==A){
                x++;
                y=0;
            }
            y=y%A;
            x=x%A;
        }
        end_row--;
        dir=4;
    }
    else if(dir==4){
        for(i=end_row; i>=start_row; i--){
            // cout<<x<<y<<dir<<endl;
            ans[x][y] = arr[i][start_col];
            y++;
            if(y==A){
                x++;
                y=0;
            }
            y=y%A;
            x=x%A;
        }
        start_col++;
        dir=1;
    }
}
return ans;

}


#2

Solved it :sweat:


#3

hi bro
what does (A,vector) means in following :
vector< vector > v (A,vector A) ?