Problem 4051 · Medium

Count Subarrays with Distant Sums

Count subarrays by turning sums into prefix differences; the ones that land near the goal form a band that is subtracted from the total.

Open the interactive visualisation