Why does the solution give runtime error if I dont mention the size of array


#1

int Solution::perfectPeak(vector &A) {
int n=A.size();
int i;
vectora;
vectorb;
a[0]=A[0];
for(i=1;i<n;i++){
a[i]=max(A[i],a[i-1]);
}
b[n-1]=A[n-1];
for(int i=n-2;i>=0;i–)
{
b[i]=min(A[i],b[i+1]);
}
for(i=1;i<n-1;i++){
if(A[i]>a[i-1] && A[i]<b[i+1])return 1;
}
return 0;
}

in the same code if I replace vector initialising statements by Vectora(n) , vectorb(n) ; this works fine , otherwise runtime error .