Minimum Positive Sum Subarray
You are given an integer array nums and two integers l and r. Your task is to find the minimum sum of a subarray whose size is between l and r (inclusive) and whose sum is greater than 0.
Return the minimum sum of such a subarray. If no such subarray exists, return -1.
A subarray is a contiguous non-empty sequence of elements within an array.
Example 1
Input
nums = [3,-2,1,4], l = 2, r = 3Output
1Out of the valid subarrays with length between 2 and 3 and positive sum,
[3, -2] has the smallest positive sum of 1.Example 2
Input
nums = [-2,2,-3,1], l = 2, r = 3Output
-1There is no subarray of length between
l and r that has a sum greater than 0, so the answer is -1.Constraints
- 1 <= nums.length <= 100
- 1 <= l <= r <= nums.length
- -1000 <= nums[i] <= 1000