37: Smallest subarray
Given an array of positive integers
and positive integer k
, find the length of the smallest
contiguous subarray of which the sum is greater or equal k
Note: If there's not such subarray, return
-1
Example 1
Input: array = [4, 1, 2, 3, 1], k = 5
Output: 2
Explanation:
[4, 1]
or[2, 3]
Example 2
Input: array = [1, 1, 2, 5], k = 30
Output: -1