Find the smallest sum of any subarray

Write codeEasy10 min

Your task

Given a non-empty list of integers (positive, negative, or zero), return the smallest possible sum of any contiguous run of one or more elements. This is the mirror image of the maximum-subarray problem: instead of the best stretch you are hunting for the worst one. For example, in [3, -4, 2, -3, -1, 7] the run [-4, 2, -3, -1] has sum -6, and no contiguous run sums lower.

Examples

min_subarray_sum(nums: list[int]) -> int
Example 1
Inputmin_subarray_sum([3, -4, 2, -3, -1, 7])
Output-6
Example 2
Inputmin_subarray_sum([2, 2, 2])
Output2