java.lang.Object
g2301_2400.s2334_subarray_with_elements_greater_than_varying_threshold.Solution

public class Solution extends Object
2334 - Subarray With Elements Greater Than Varying Threshold.<p>Hard</p> <p>You are given an integer array <code>nums</code> and an integer <code>threshold</code>.</p> <p>Find any subarray of <code>nums</code> of length <code>k</code> such that <strong>every</strong> element in the subarray is <strong>greater</strong> than <code>threshold / k</code>.</p> <p>Return <em>the <strong>size</strong> of <strong>any</strong> such subarray</em>. If there is no such subarray, return <code>-1</code>.</p> <p>A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,3,4,3,1], threshold = 6</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> The subarray [3,4,3] has a size of 3, and every element is greater than 6 / 3 = 2.</p> <p>Note that this is the only valid subarray.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [6,5,6,5,8], threshold = 7</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> The subarray [8] has a size of 1, and 8 > 7 / 1 = 7. So 1 is returned.</p> <p>Note that the subarray [6,5] has a size of 2, and every element is greater than 7 / 2 = 3.5.</p> <p>Similarly, the subarrays [6,5,6], [6,5,6,5], [6,5,6,5,8] also satisfy the given conditions.</p> <p>Therefore, 2, 3, 4, or 5 may also be returned.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums[i], threshold <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • validSubarraySize

      public int validSubarraySize(int[] nums, int threshold)