Shortest Reaching Subarray (Negatives)
Values may be negative. Find the length of the shortest contiguous subarray with sum at least K, or −1.
Input: the first line has N and K; the second line has N integers.
Output: the minimum length, or −1.
Constraints:
- 1 ≤ N ≤ 105
- |ai| ≤ 104
- |K| ≤ 109
Sample Tests
Input 1
5 3 2 -1 2 -3 4
Output 1
1
Input 2
3 100 1 2 3
Output 2
-1
Discussion (opens after you solve — no spoilers before)
No comments yet.