Each operation strips one element off the front or the back and subtracts it from x; you want the fewest operations that land x on exactly zero. The removed set straddles the two ends, so it is not a window — but the untouched middle is, and it must sum to exactly total − x. Deriving that number is the whole problem: after it, you are just finding the longest subarray with a given sum, and answer = n − longestMiddle (or −1 if no middle hits the number). Note the pairing with LC 1423: same complement move, but there the middle had a fixed width you slid, and here it is variable — grow on the right, shrink on the left whenever you overshoot. Both live in the syllabus so you meet the trick in both shapes.
target = total − x; the middle is variable-width here, unlike LC 1423's fixed one.
Only sound because every value is positive — that is what makes the sum monotone in the boundaries.