Loading...
You are given an integer array nums (values may be negative) and a positive integer k.
nums
k
Return the length of the shortest non-empty contiguous subarray of nums whose sum is at least k, or -1 if no such subarray exists.
-1
Input: nums = [1], k = 1 Output: 1
Input: nums = [1,2], k = 4 Output: -1
Input: nums = [2,-1,2], k = 3 Output: 3 Explanation: Only the whole array reaches sum 3, since the negative middle element must be bridged.
nums.length
nums[i]
Click "Run" to test with sample cases or "Submit" to run all tests.