Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int countSubarray(int arr[],
- int n, int k)
- {
- int start = 0, end = 0;
- int count = 0, sum = arr[0];
- while (start < n && end < n) {
- if (sum < k) {
- end++;
- if (end >= start)
- count += end - start;
- if (end < n)
- sum += arr[end];
- }
- else {
- sum -= arr[start];
- start++;
- }
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement