Use a monotonic increasing queue of indices by prefix sum value. Two key observations:
If and , you never need . Why? Index is closer to future values AND has equal or smaller prefix sum, so it gives a shorter valid subarray.
Once index forms a valid subarray with (meaning ), you can remove from the deque. Future positions would give longer subarrays with .