@@ -14,7 +14,7 @@ 4. We will iterate through the array and calculate the sum of the next k element
14
14
*/
15
15
public class Solution {
16
16
public int NumOfSubarrays ( int [ ] arr , int k , int threshold ) {
17
- int i , j , c , res , sum ; // Initialize i, j, c, res, and sum to 0.
17
+ int i , j , c , res , sum ; // Initialize i, j, c, res, and sum to 0.
18
18
i = c = sum = res = 0 ; // Initialize i, c, sum, and res to 0.
19
19
j = i + k - 1 ; // Initialize j to i + k - 1.
20
20
@@ -23,18 +23,18 @@ public int NumOfSubarrays(int[] arr, int k, int threshold) {
23
23
c ++ ; // Increment c.
24
24
}
25
25
26
- res = ( sum / k ) >= threshold ? 1 : 0 ; // Check if the average is greater than or equal to the threshold and increment the result accordingly.
26
+ res = ( sum / k ) >= threshold ? 1 : 0 ; // Check if the average is greater than or equal to the threshold and increment the result accordingly.
27
27
28
- while ( j < arr . Length ) { // Iterate through the array and calculate the sum of the next k elements.
28
+ while ( j < arr . Length ) { // Iterate through the array and calculate the sum of the next k elements.
29
29
sum = sum - arr [ i ++ ] ; // Subtract the element at index i from the sum and increment i.
30
30
j ++ ; // Increment j.
31
- if ( j < arr . Length ) { // Check if j is less than the length of the array.
31
+ if ( j < arr . Length ) { // Check if j is less than the length of the array.
32
32
sum = sum + arr [ j ] ; // Add the element at index j to the sum.
33
33
}
34
34
else {
35
35
break ; // Break the loop if j is equal to or greater than the length of the array.
36
36
}
37
- if ( ( sum / k ) >= threshold ) { // Check if the average is greater than or equal to the threshold.
37
+ if ( ( sum / k ) >= threshold ) { // Check if the average is greater than or equal to the threshold.
38
38
res ++ ; // Increment the result.
39
39
}
40
40
}