This one took me a while to even see the path forward.
Use a sliding window with a monotonic deque to maintain candidate starting indices, achieving O(n) time. For each right endpoint, update the deque to keep indices with increasing prefix sums, then find the smallest index where prefix sum difference >= T. Track the minimum length and return -1 if none found.
Pro tip: Emphasize that the deque stores indices of increasing prefix sums, allowing efficient removal of dominated candidates. This demonstrates deep understanding of monotonic queues and amortized O(n) analysis.
Restate the problem: find the shortest contiguous subarray with sum >= T, return -1 if none. Confirm that negative numbers are allowed and that T can be negative.
Mention brute-force O(n^2) and prefix-sum with binary search O(n log n) as baselines, then explain why they are suboptimal for large n.
Explain that a deque of indices with increasing prefix sums allows finding the smallest valid start for each end in amortized O(1).
Iterate right from 0 to n-1: update deque by removing indices with prefix sum >= current prefix sum; then while deque front satisfies prefix[right+1] - prefix[front] >= T, update min length and pop front.
Argue that each index is added and removed at most once, giving O(n) time and O(n) space. Prove correctness by showing the deque maintains all potentially optimal starts.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.