FPEvalDataset/LeetCodeProblem
0302
1{2 "id": 3644,3 "name": "minimum_positive_sum_subarray",4 "difficulty": "Easy",5 "link": "https://leetcode.com/problems/minimum-positive-sum-subarray/",6 "date": "2024-11-17 00:00:00",7 "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`",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "nums = [3, -2, 1, 4], l = 2, r = 3",12 "output": "1 "13 },14 {15 "label": "Example 2",16 "input": "nums = [-2, 2, -3, 1], l = 2, r = 3",17 "output": "-1 "18 },19 {20 "label": "Example 3",21 "input": "nums = [1, 2, 3, 4], l = 2, r = 4",22 "output": "3 "23 }24 ],25 "private_test_cases": [26 {27 "input": [28 [29 -484,30 -678,31 -161,32 772,33 485,34 954,35 849,36 -120,37 -38138 ],39 9,40 941 ],42 "output": 123643 },44 {45 "input": [46 [47 500,48 204,49 -946,50 751,51 -938,52 -95,53 -751,54 -731,55 323,56 207,57 41258 ],59 5,60 761 ],62 "output": -163 },64 {65 "input": [66 [67 104,68 328,69 -640,70 -399,71 -4772 ],73 3,74 475 ],76 "output": -177 },78 {79 "input": [80 [81 604,82 -245,83 -778,84 618,85 -603,86 185,87 -844,88 978,89 -477,90 336,91 -83492 ],93 7,94 1195 ],96 "output": 19397 },98 {99 "input": [100 [101 225,102 122,103 -360,104 -26,105 147,106 -688,107 602,108 749,109 -194,110 -122,111 795,112 835,113 -377,114 125,115 -387,116 60,117 -517,118 256,119 -852,120 -744,121 920,122 582,123 -204,124 34,125 748,126 -459,127 113,128 97,129 -655,130 786,131 -946,132 187,133 -597,134 -818,135 -28,136 523,137 -227,138 -424,139 262,140 788,141 209,142 -492,143 373,144 -258,145 289,146 987,147 941,148 -515,149 -787,150 -215,151 878,152 -652,153 873,154 -214,155 255,156 -237,157 -702,158 879,159 70,160 -718,161 -333162 ],163 24,164 49165 ],166 "output": 12167 },168 {169 "input": [170 [171 -715,172 -35,173 301,174 182,175 738,176 -819,177 682,178 627,179 399,180 -431181 ],182 7,183 9184 ],185 "output": 334186 },187 {188 "input": [189 [190 -737,191 -966,192 129,193 -822,194 447,195 700,196 317,197 954,198 -551,199 820,200 -436,201 -467,202 26,203 405,204 38,205 96,206 -671,207 479,208 842,209 101,210 852,211 557,212 795,213 -872,214 -451,215 -511,216 -253217 ],218 5,219 7220 ],221 "output": 98222 },223 {224 "input": [225 [226 -98,227 580,228 -919,229 -837,230 510,231 238,232 259,233 -770,234 -754,235 -243,236 -950,237 -923,238 -218,239 -947,240 727,241 981,242 -313,243 918244 ],245 6,246 12247 ],248 "output": 225249 },250 {251 "input": [252 [253 -169,254 671,255 -294,256 244257 ],258 2,259 4260 ],261 "output": 208262 },263 {264 "input": [265 [266 -830,267 -948,268 691,269 369,270 799,271 -235,272 -864,273 270,274 -226,275 -147,276 -146,277 -658,278 966,279 -313,280 493,281 -246,282 842,283 949,284 -42,285 -392,286 604,287 -839,288 -325,289 898,290 698,291 -43,292 219,293 -863,294 90,295 -900,296 588,297 -989,298 -526,299 -258,300 81,301 83,302 -423,303 -741,304 200,305 730,306 -359,307 851,308 -345,309 -764,310 -614,311 -938,312 -551,313 594,314 -739,315 471,316 57,317 4,318 -756,319 -770,320 -611,321 -156,322 257,323 -452,324 798,325 -815,326 788,327 -89,328 -73,329 663,330 -353,331 353,332 685,333 357,334 -206,335 -887,336 -372,337 -743,338 -679,339 344,340 347,341 715,342 -892,343 -202,344 -801345 ],346 50,347 56348 ],349 "output": -1350 }351 ],352 "haskell_template": "minimumSumSubarray :: [Int] -> Int -> Int -> Int\nminimumSumSubarray nums l r ",353 "ocaml_template": "let minimumSumSubarray (nums: int list) (l: int) (r: int) : int = ",354 "scala_template": "def minimumSumSubarray(nums: List[Int],l: Int,r: Int): Int = { \n \n}",355 "java_template": "class Solution {\n public int minimumSumSubarray(List<Integer> nums, int l, int r) {\n \n }\n}",356 "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 "357}