Count Subarrays With Score Less Than K LeetCode solution in Java
1class Solution {2public long countSubarrays(int[] nums, long k) {3int i = 0;4int j = 0;5long max = 0;6long operation = 0;78while (j < nums.length) {9operation += nums[j];10while (operation * (j - i + 1) >= k) {11operation -= nums[i];12i++;13}14max += j - i + 1;15j++;16}17return max;18}19}