Ctrl K

Smallest Positive Slice Sum

Easy
You are given an integer array changes and two integers min_len and max_len. Consider every contiguous slice of the array whose length is between min_len and max_len inclusive and whose sum is **strictly greater than zero**. Return the smallest such sum, or -1 if no slice qualifies.
Example 1
changes=[4, -3, 2, -2, 5], min_len=2, max_len=3 → 1

The slice [4, -3] sums to 1; no slice of length 2 to 3 has a smaller positive sum.

Example 2
changes=[-5, 1, -4], min_len=1, max_len=3 → 1

The only slice with a positive sum is [1].

Example 3
changes=[-1, -1, 0], min_len=2, max_len=3 → -1
Constraints
  • 1 ≤ len(changes) ≤ 100
  • 1 ≤ min_len ≤ max_len ≤ len(changes)
  • -1000 ≤ changes[i] ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsShortest Stretch to the Goal MediumWindows With a Small Product MediumShortest Stretch Reaching a Total HardWindows With an Exact Alarm Count MediumLight Every Lamp With a Window Hard
loading Python…
Input
changes=[4, -3, 2, -2, 5], min_len=2, max_len=3
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 116 tests on the server, hidden ones included.