Why this O(n) solution not working


#1

int Solution::numRange(vector &A, int B, int C) {
int i=0,j=0,k=0,a=0,n;
n = A.size();
while(i<n&&j<n&&j>=i){
a = a + A[j];
if(a<B) j++;
else if(a>C) {
if(i==j) j++;
else a=a-A[j];
a=a-A[i];
i++;
}
else if (a>=B&&a<=C) {
k++;
j++;
if (j==n) {
j–;
a=a-A[i]-A[j];
i++;
}
}
}
return k;
}