Solved it by taking a dummy(temp) vector and storing current subarray in it. Not able to find its Time Complexity


#1

int Solution::numRange(vector &A, int B, int C) {
vector temp;
int sum=0,count=0;
for(int i=0;i<A.size();i++){
if(sum+A[i]>C){
while(temp.size()>0 && sum+A[i]>C){
sum-=temp[0];
temp.erase(temp.begin());
}
}
if(sum+A[i]<B){
temp.push_back(A[i]);
sum+=A[i];
continue;
}
if(sum+A[i]>=B && sum+A[i]<=C){
count++;
temp.push_back(A[i]);
sum+=A[i];
int tempsum=sum;
for(int i=0;i<temp.size();i++){
tempsum-=temp[i];
if(tempsum>=B && tempsum<=C){
count++;
}
}
}
}
return count;
}