You'll use a deque to maintain candidate starting positions. The core idea: if prefix[j] >= prefix[i] and j > i, position i is never useful. For each position k, you do two things. First, remove positions at the back of Second, check positions at the front: if k. Pos >= targetLength and prefix[k] - prefix[pos] meets the sum requirement, update your answer. Each position enters and leaves This is a classic sliding window with monotonic deque pattern. You maintain candidates and prune them based on both value and position constraints. Time: . Space: .
Time complexity: .
Space complexity: .