Count Subarrays With Score Less Than K LeetCode solution in JavaScript
1var countSubarrays = function (nums, k) {2let curentRunningSum = 0,3result = 0,4windowEnd = 0,5windowStart = 0;6while (windowEnd < nums.length) {7curentRunningSum += nums[windowEnd];8while (curentRunningSum * (windowEnd - windowStart + 1) >= k)9curentRunningSum -= nums[windowStart++];10result += windowEnd - windowStart + 1;11windowEnd++;12}13return result;14};