Subarray With Elements Greater Than Varying Threshold
You are given an integer array nums and an integer threshold.
Find any subarray of nums of length k such that every element in the subarray is greater than threshold / k.
Return the size of any such subarray. If there is no such subarray, return -1.
A subarray is a contiguous non-empty sequence of elements within an array.
Example 1
Input
nums = [1,3,4,3,1], threshold = 6Output
3The subarray [3, 4, 3] has size 3, and every element is greater than 6 / 3 = 2.
Example 2
Input
nums = [6,5,6,5,8], threshold = 7Output
1The subarray [8] has size 1, and 8 is greater than 7 / 1 = 7, though other valid subarray sizes may also be returned.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i], threshold <= 10^9