package leetcode;

/**
 * https://leetcode.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold/
 */
public class Problem1343 {
    public int numOfSubarrays(int[] arr, int k, int threshold) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1343 prob = new Problem1343();
        System.out.println(prob.numOfSubarrays(new int[]{2,2,2,2,5,5,5,8}, 3, 4)); // 3
        System.out.println(prob.numOfSubarrays(new int[]{1,1,1,1,1}, 1, 0)); // 5
        System.out.println(prob.numOfSubarrays(new int[]{11,13,17,23,29,31,7,5,2,3}, 3, 5)); // 6
        System.out.println(prob.numOfSubarrays(new int[]{7,7,7,7,7,7,7}, 7, 7)); // 1
        System.out.println(prob.numOfSubarrays(new int[]{4,4,4,4}, 4, 1)); // 1
    }
}

@@ -236,485 +236,440 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1343 prob = new Problem1343();%0A        System.out.println(prob.numOfSubarrays(new int%5B%5D%7B2,2,2,2,5,5,5,8%7D, 3, 4)); // 3%0A        System.out.println(prob.numOfSubarrays(new int%5B%5D%7B1,1,1,1,1%7D, 1, 0)); // 5%0A        System.out.println(prob.numOfSubarrays(new int%5B%5D%7B11,13,17,23,29,31,7,5,2,3%7D, 3, 5)); // 6%0A        System.out.println(prob.numOfSubarrays(new int%5B%5D%7B7,7,7,7,7,7,7%7D, 7, 7
+int%5B%5D prefixSums = new int%5Barr.length%5D;%0A        for (int i = 0; i %3C arr.length; i++) %7B%0A            if (i == 0) %7B%0A                prefixSums%5Bi%5D = arr%5Bi%5D;%0A            %7D else %7B%0A                prefixSums%5Bi%5D += prefixSums%5Bi - 1%5D + arr%5Bi%5D;%0A            %7D%0A        %7D%0A        int answer = 0;%0A        int j = -1;%0A        for (int i = k - 1; i %3C arr.length; i++) %7B%0A            int average = (prefixSums%5Bi%5D - (j == -1 ? 0 : prefixSums%5Bj%5D
 ))
-;
  /
-/ 1
+ k;
 %0A   
@@ -677,79 +677,129 @@
     
-System.out.println(prob.numOfSubarrays(new int%5B%5D%7B4,4,4,4%7D, 4, 1)); // 1
+    if (average %3E= threshold) %7B%0A                answer++;%0A            %7D%0A            j++;%0A        %7D%0A        return answer;
 %0A   

Solve problem 1343