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
Inputnums = [1,3,4,3,1], threshold = 6
Output3
The subarray [3, 4, 3] has size 3, and every element is greater than 6 / 3 = 2.
Example 2
Inputnums = [6,5,6,5,8], threshold = 7
Output1
The 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

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate