⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 18m 47s17 days 22 hours 18 minutes 47 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 18m 47s17 days 22 hours 18 minutes 47 seconds.

Sign in to watch this lesson
Algorithms - Arrays · 4:00
Counting subarrays that sum to k, even with negative numbers, in one pass: a subarray sum is the difference of two prefixes, so we sweep the prefixes, look back k in a tally of the ones already seen, and only then insert the new one. We trace it on a small array, cover the pitfalls (the starting zero, look-up order, negative remainders in C++), extend it to divisibility, longest subarrays, balanced windows and XOR, and time it against checking every pair on a Mac.