You may find this solution helpful , sliding window concept using two pointer


#1
int Solution::numRange(vector<int> &A, int B, int C) {
    int ans = 0;
    int n = A.size();
    if(n==1){
        if(A[0]>=B&&A[0]<=C)return 1;
        return 0;
    }
    int j = 0;int sum = 0;
    int i =0;
        while(i<n){
           // cout<<sum<<" "<<ans<<' ';
           // cout<<i<<' '<<j  <<'\n';
			if(sum>C){sum=0;i++;j = i;}
            else {sum+=A[j];j++;}
            if(sum<=C&&sum>=B)ans++;

            if(j==n){sum=0;i++;j=i;}

        }
    return ans;
    
}