<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>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,3,4,3,1], threshold = 6
<strong>Output:</strong> 3
<strong>Explanation:</strong> The subarray [3,4,3] has a size of 3, and every element is greater than 6 / 3 = 2.
Note that this is the only valid subarray.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [6,5,6,5,8], threshold = 7
<strong>Output:</strong> 1
<strong>Explanation:</strong> The subarray [8] has a size of 1, and 8 &gt; 7 / 1 = 7. So 1 is returned.
Note that the subarray [6,5] has a size of 2, and every element is greater than 7 / 2 = 3.5. 
Similarly, the subarrays [6,5,6], [6,5,6,5], [6,5,6,5,8] also satisfy the given conditions.
Therefore, 2, 3, 4, or 5 may also be returned.</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i], threshold &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution:
    def validSubarraySize(self, nums: List[int], threshold: int) -> int:
        cur_left = 0
        cur_right = 0

        for min_index in range(len(nums)):
            # print(min_index, nums[min_index])
            if min_index == 0:
                for i in range(min_index + 1, len(nums)):
                    if nums[i] >= nums[min_index]:
                        # print("larger", i, nums[i], nums[min_index])
                        cur_right += 1
                    else:
                        break
            elif nums[min_index] > nums[min_index - 1]:
                cur_left = min_index
                cur_right = min_index
                for i in range(min_index + 1, len(nums)):
                    if nums[i] >= nums[min_index]:
                        cur_right += 1
                    else:
                        break
            else:
                while cur_left - 1 >= 0:
                    if nums[min_index] <= nums[cur_left - 1]:
                        cur_left -= 1
                    else:
                        break
                while cur_right + 1 < len(nums):
                    if nums[min_index] <= nums[cur_right + 1]:
                        cur_right += 1
                    else:
                        break
            
            # print(nums[min_index], cur_left, cur_right)
            if nums[min_index] > threshold / (cur_right - cur_left + 1):
                return cur_right - cur_left + 1
        return -1



# def find_size(nums, l, r, threshold):
#     length = r - l + 1
#     if length <= 0:
#         return -1
    
#     # min_num = 2**31 - 1
#     # min_id = -1
#     dt = threshold / length
#     for i in range(l, r + 1):
#         if nums[i] <= dt:
#             # min_num = nums[i]
#             # min_id = i
#             left_len = find_size(nums, l, i - 1, threshold)
#             if left_len != -1:
#                 return left_len
#             right_len = find_size(nums, i + 1, r, threshold)
#             # if right_len != -1:
#             return right_len
#             # return -1
    
#     return length
        

# class Solution:
#     def validSubarraySize(self, nums: List[int], threshold: int) -> int:
        
#         return find_size(nums, 0, len(nums) - 1, threshold)

#         # length = len(nums)
#         # if length == 0:
#         #     return -1
        
#         # min_num = 2**31 - 1
#         # min_id = -1
#         # for i in range(length):
#         #     if nums[i] < threshold / length:
#         #         min_num = nums[i]
#         #         min_id = i
#         #         break
        
#         # if min_id == -1:
#         #     return length
#         # else:
#         #     left_len = self.validSubarraySize(nums[0:min_id], threshold)
#         #     if left_len != -1:
#         #         return left_len
#         #     right_len = self.validSubarraySize(nums[min_id + 1:], threshold)
#         #     if right_len != -1:
#         #         return right_len
#         #     else:
#         #         return -1
1103