1343. Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold Medium
1/**
2 * [1343] Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold
3 *
4 * Given an array of integers arr and two integers k and threshold, return the number of sub-arrays of size k and average greater than or equal to threshold.
5 *
6 * Example 1:
7 *
8 * Input: arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
9 * Output: 3
10 * Explanation: Sub-arrays [2,5,5],[5,5,5] and [5,5,8] have averages 4, 5 and 6 respectively. All other sub-arrays of size 3 have averages less than 4 (the threshold).
11 *
12 * Example 2:
13 *
14 * Input: arr = [11,13,17,23,29,31,7,5,2,3], k = 3, threshold = 5
15 * Output: 6
16 * Explanation: The first 6 sub-arrays of size 3 have averages greater than 5. Note that averages are not integers.
17 *
18 *
19 * Constraints:
20 *
21 * 1 <= arr.length <= 10^5
22 * 1 <= arr[i] <= 10^4
23 * 1 <= k <= arr.length
24 * 0 <= threshold <= 10^4
25 *
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold/
30// discuss: https://leetcode.com/problems/number-of-sub-arrays-of-size-k-and-average-greater-than-or-equal-to-threshold/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35 pub fn num_of_subarrays(arr: Vec<i32>, k: i32, threshold: i32) -> i32 {
36 0
37 }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_1343() {
48 }
49}
50
Back
© 2025 bowen.ge All Rights Reserved.