Module 7 · Sliding Window · Sliding Window Advanced

Count the number of good subarrays

Grow the window until it has at least k pairs of equal values. Then every subarray that starts at left and ends at right - 1 or later is good too — adding numbers never removes a pair — so count them all at once, remove nums[left], and repeat while it stays good.