You're given an integer array nums and an integer threshold. Your mission is to find any subarray of length k where every single element is greater than threshold / k.
The twist? The threshold varies based on the subarray length! For a subarray of length k, each element must exceed threshold / k. This means longer subarrays have more lenient per-element requirements, while shorter subarrays demand higher individual values.
Goal: Return the size of any such valid subarray, or -1 if none exists.
Example: If threshold = 10 and you're checking a subarray of length 2, each element must be > 5. For length 5, each element must be > 2.
Input & Output
Visualization
Time & Space Complexity
O(log n) binary search iterations, each requiring O(n) sliding window validation
Only constant extra space for binary search variables
Constraints
- 1 โค nums.length โค 105
- 1 โค nums[i] โค 109
- 1 โค threshold โค 1015
- Note: The threshold can be very large, requiring careful handling of integer division