Runtime error for big values like 80


#1

vector<vector > Solution::generateMatrix(int A) {
vector<vector > arr;
int k=1;
int a=0,x=0,y=A-1,z=A-1,w=0;
while(k<=A*A){
for(int i=0+a;i<A-a;i++){
arr[x][i]=k;
k++;
}
x++;
for(int i=1+a;i<A-1-a;i++){
arr[i][y]=k;
k++;
}
y–;
for(int i=A-1-a;i>=0+a;i–){
arr[z][i]=k;
k++;
}
z–;
for(int i=A-1-1-a;i>0+a;i–){
arr[i][w]=k;
k++;
}
w++;
}
return arr;
}


#3

there is some mistake in your x,y,w,z increment or decrement after each loop, do check it out.