You are given an array of integers nums and an integer k, find the length of the shortest contiguous subarray whose sum is exactly k. If there is no such subarray, return -1.
nums = [1, 2, 3, 4, 5]
k = 9
2
The subarray [4, 5] has a sum of 9 and is the shortest such subarray.
nums = [1, -1, 5, -2, 3]
k = 3
1
The subarray [3] has a sum of 3 and is the shortest such subarray.
nums = [1, 2, 3]
k = 10
-1
No subarray sums to 10.
nums = [1, 2, 3, 4, 5]
k = 9
2