Backend Engineer
Senior
programming
Given an integer array nums, return the number of contiguous subarrays that have an average value greater than or equal to the given threshold. The average is defined by the sum of the elements divided by the number of elements in the subarray. You must solve it in O(n) time complexity. ### Constraints: - 1 <= nums.length <= 10^5 - 1 <= nums[i] <= 100 - 0 <= threshold <= 100 ### Examples: 1. Input: nums = [1, 2, 3, 4], threshold = 2 Output: 5 Explanation: Subarrays [2], [3], [4], [1, 2], and [2, 3] have averages greater than or equal to 2. 2. Input: nums = [1, 3, 2, 5, 4], threshold = 3 Output: 8 Explanation: Subarrays with averages greater than or equal to 3 are counted.
Suggested Answer