{ "id": 3644, "name": "minimum_positive_sum_subarray", "difficulty": "Easy", "link": "https://leetcode.com/problems/minimum-positive-sum-subarray/", "date": "2024-11-17 00:00:00", "task_description": "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 = 3 **Output:** 1 **Explanation:** The subarrays of length between `l = 2` and `r = 3` where the sum is greater than 0 are: `[3, -2]` with a sum of 1 `[1, 4]` with a sum of 5 `[3, -2, 1]` with a sum of 2 `[-2, 1, 4]` with a sum of 3 Out of these, the subarray `[3, -2]` has a sum of 1, which is the smallest positive sum. Hence, the answer is 1. **Example 2:** **Input:** nums = [-2, 2, -3, 1], l = 2, r = 3 **Output:** -1 **Explanation:** There is no subarray of length between `l` and `r` that has a sum greater than 0. So, the answer is -1. **Example 3:** **Input:** nums = [1, 2, 3, 4], l = 2, r = 4 **Output:** 3 **Explanation:** The subarray `[1, 2]` has a length of 2 and the minimum sum greater than 0. So, the answer is 3. **Constraints:** `1 <= nums.length <= 100` `1 <= l <= r <= nums.length` `-1000 <= nums[i] <= 1000`", "public_test_cases": [ { "label": "Example 1", "input": "nums = [3, -2, 1, 4], l = 2, r = 3", "output": "1 " }, { "label": "Example 2", "input": "nums = [-2, 2, -3, 1], l = 2, r = 3", "output": "-1 " }, { "label": "Example 3", "input": "nums = [1, 2, 3, 4], l = 2, r = 4", "output": "3 " } ], "private_test_cases": [ { "input": [ [ -484, -678, -161, 772, 485, 954, 849, -120, -381 ], 9, 9 ], "output": 1236 }, { "input": [ [ 500, 204, -946, 751, -938, -95, -751, -731, 323, 207, 412 ], 5, 7 ], "output": -1 }, { "input": [ [ 104, 328, -640, -399, -47 ], 3, 4 ], "output": -1 }, { "input": [ [ 604, -245, -778, 618, -603, 185, -844, 978, -477, 336, -834 ], 7, 11 ], "output": 193 }, { "input": [ [ 225, 122, -360, -26, 147, -688, 602, 749, -194, -122, 795, 835, -377, 125, -387, 60, -517, 256, -852, -744, 920, 582, -204, 34, 748, -459, 113, 97, -655, 786, -946, 187, -597, -818, -28, 523, -227, -424, 262, 788, 209, -492, 373, -258, 289, 987, 941, -515, -787, -215, 878, -652, 873, -214, 255, -237, -702, 879, 70, -718, -333 ], 24, 49 ], "output": 12 }, { "input": [ [ -715, -35, 301, 182, 738, -819, 682, 627, 399, -431 ], 7, 9 ], "output": 334 }, { "input": [ [ -737, -966, 129, -822, 447, 700, 317, 954, -551, 820, -436, -467, 26, 405, 38, 96, -671, 479, 842, 101, 852, 557, 795, -872, -451, -511, -253 ], 5, 7 ], "output": 98 }, { "input": [ [ -98, 580, -919, -837, 510, 238, 259, -770, -754, -243, -950, -923, -218, -947, 727, 981, -313, 918 ], 6, 12 ], "output": 225 }, { "input": [ [ -169, 671, -294, 244 ], 2, 4 ], "output": 208 }, { "input": [ [ -830, -948, 691, 369, 799, -235, -864, 270, -226, -147, -146, -658, 966, -313, 493, -246, 842, 949, -42, -392, 604, -839, -325, 898, 698, -43, 219, -863, 90, -900, 588, -989, -526, -258, 81, 83, -423, -741, 200, 730, -359, 851, -345, -764, -614, -938, -551, 594, -739, 471, 57, 4, -756, -770, -611, -156, 257, -452, 798, -815, 788, -89, -73, 663, -353, 353, 685, 357, -206, -887, -372, -743, -679, 344, 347, 715, -892, -202, -801 ], 50, 56 ], "output": -1 } ], "haskell_template": "minimumSumSubarray :: [Int] -> Int -> Int -> Int\nminimumSumSubarray nums l r ", "ocaml_template": "let minimumSumSubarray (nums: int list) (l: int) (r: int) : int = ", "scala_template": "def minimumSumSubarray(nums: List[Int],l: Int,r: Int): Int = { \n \n}", "java_template": "class Solution {\n public int minimumSumSubarray(List nums, int l, int r) {\n \n }\n}", "python_template": "class Solution(object):\n def minimumSumSubarray(self, nums, l, r):\n \"\"\"\n :type nums: List[int]\n :type l: int\n :type r: int\n :rtype: int\n \"\"\"\n " }