You'll use a deque to maintain candidate starting positions. The core idea: if and , position is never useful.
For each position , you do two things. First, remove positions from the back of the deque whose prefix sum is . They will never be optimal starting points because is closer and has a smaller or equal prefix sum. Second, check positions at the front of the deque: while , you have a valid subarray. Update your answer with , then pop the front (no future will do better with that index).
Each position enters the deque once and leaves once. This gives total work across all iterations.
Time complexity: .
Space complexity: for the prefix array and deque.