Return the length of the shortest non-empty contiguous subarray of nums whose sum is at least k, or -1 if there is none. The numbers can be negative, so the usual sliding window does not work.
For nums = [2, -1, 2] and k = 3 the answer is 3.
The starter code tries every start. It is correct but too slow for long arrays.
Example 1
Input:
shortest_subarray_sum_k([2, -1, 2], 3)
Output:
3
Example 2
Input:
shortest_subarray_sum_k([1], 2)
Output:
-1
1 <= len(nums) <= 200000-10**5 <= nums[i] <= 10**51 <= k <= 10**9No results yet
Run your code to check it against the examples, or submit to run every test.