Why does the sliding window algorithm guarantee that we visit the largest valid subarray?
The sliding window algorithm iterates through the largest valid subarrays ending at a specific element of the array (see Which subarrays does the Sliding Window Algorithm actually visit?).
And because the largest valid subarray must be ending at some element in the array, we can say that the sliding window algorithm at one of the iterations visits the largest valid subarray.