Subarray Sum Equals K (LC #560) tests the prefix sum with hash map pattern. A subarray from to sums to if prefixSum[] minus prefixSum[] equals . Rearranging: we need prefixSum[] minus to exist as a previous prefix sum. Use a hash map to count prefix sums seen so far. For each position, add the count of (currentSum minus ) to your answer. Initialize the map with sum appearing once. This runs in time and space. Meta asked this in E6 full loops.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/meta-interview-prep/arrays-strings/subarray-sum-equals-k
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████████████████████████████████████████████████████████████████████████████