Skip to content

Practice Minimum Positive Sum Subarray

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3364
LeetCode Problem

Minimum Positive Sum Subarray

Problem Statement

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.

Source: Minimum Positive Sum Subarray on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [3, -2, 1, 4], l = 2, r = 3
Output
1

# Example 2

Input
nums = [-2, 2, -3, 1], l = 2, r = 3
Output
-1

# Example 3

Input
nums = [1, 2, 3, 4], l = 2, r = 4
Output
3

Constraints

1 <= nums.length <= 100
1 <= l <= r <= nums.length
-1000 <= nums[i] <= 1000

Related LeetCode Problems

Practice more problems similar to Minimum Positive Sum Subarray .

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.