arrayscomplexityhashing
Count target-sum subarrays without checking every range
Anonymous
Scan prefix sums from left to right. Before storing the current prefix, add the frequency of prefix minus target to the answer; each prior prefix with that value starts a matching subarray. Seed the frequency map with zero occurring once so ranges beginning at index zero count too. Expected O(n) time and O(n) space with a hash map.
0