C++ solution in O(n), by sliding window method


#1
int Solution::solve(vector<int> &A, int B) {

int n = A.size();
int ans = 0, sum = 0;
int start = 0, end = 0;
while(end < n)
{
    if(sum + A[end] < B)
    {
        sum += A[end];
        ans += (end - start+1);
        end++;
        
    }
    else
    {
        sum -= A[start];
        start++;
    }
}
return ans;
}

#2

Yes it cover corner cases also.


#3

It gives answer as 0, which is correct, check once again.