You are given an integer array nums and two integers l and r.
Your goal is to look at all subarrays whose lengths fall between l and r (both inclusive).
Among these subarrays, you must consider only the ones where the total sum is strictly greater than 0.
Out of all such subarrays, find the one with the smallest positive sum.
If no subarray within the allowed size range has a sum above zero, return -1.
A subarray is defined as a continuous block of elements taken from the array.
Input: nums = [2, -1, -1, 3], l = 2, r = 3
Output: 1
Explanation:
Valid windows with positive sums: [2, -1] → 1 [-1, 3] → 2 [-1, -1, 3] → 1 The smallest positive sum is 1.
Input: nums = [-1, -2, -3], l = 1, r = 2
Output: -1
Explanation:
No subarray of size 1 or 2 has a sum > 0.
Input: nums = [4, -4, 5, -1, 2], l = 1, r = 4
Output: 2
Explanation:
Some positive-sum windows include: [4] → 4 [5] → 5 [5, -1] → 4 [-1, 2] → 1 [5, -1, 2] → 6 The smallest sum > 0 is from [-1, 2] → 1. But because length must be between 1 and 4, 1 is valid → answer = 1. (You can modify if you want exact length rules.)
Accepted:
Submission: