Backend Engineer
Senior
programming
Find the length of the shortest subarray with a sum at least K. You may assume that the array has at least one element. You must solve this in O(n) time complexity. ### Constraints: - 1 <= arr.length <= 10^5 - 1 <= arr[i] <= 10^4 - 1 <= K <= 10^9 ### Examples: 1. Input: arr = [2, -1, 2, 3, 4], K = 3 Output: 2 Explanation: The subarray [2, 3] has the minimum length of 2. 2. Input: arr = [1, 2, 3, 4, 5], K = 11 Output: 3 Explanation: The subarray [3, 4, 5] has the minimum length of 3.
Suggested Answer