FAANG · LeetCode #862
Shortest Subarray with Sum at Least K — three-stage drill
1The ProblemHard
Shortest Subarray with Sum at Least K
Shortest subarray with sum ≥ k — but values can be negative.
Examples
[3,-2,5], k=4→ 1[1,2], k=4→ -1
constraintValues may be negative.
2The PatternTIME O(n) · SPACE O(n)
Monotonic Deque
A deque kept sorted by popping the back — the front is always the best candidate.
Problems using this pattern
3The SolutionRESULT → 1
Step through it
i=0 (P=0): deque empty → push index 0
Step 1 / 8
Arrow keys to navigate · escape to reset