Leetcode Problem 862. Shortest Subarray with Sum at Least K
862. Shortest Subarray with Sum at Least K
Leetcode Solutions
Key approach of the solution: Sliding Window with Monoqueue
Initialize a deque to store indices of prefix sums in increasing order.
Initialize variables for the prefix sum and the minimum length found so far.
Iterate through the array, updating the prefix sum.
While the current prefix sum minus the prefix sum at the deque's front index is at least k, update the minimum length and pop from the front of the deque.
Maintain the monoqueue by popping from the back while the current prefix sum is less than or equal to the prefix sums at the indices stored in the deque.
Add the current index to the back of the deque.
After iterating through the array, check if the minimum length was updated and return it, or return -1 if no such subarray was found.