01 · Question
Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals k.
02 · Analysis
A subarray sum equals k when the current prefix minus an earlier prefix equals k. Store frequencies of earlier prefix sums, initialized with {0:1}. Query current-k before inserting current to exclude an empty range, especially for k=0. Repeated prefixes represent different starts and must all count. Expected O(n) time, O(n) auxiliary space; signed values are allowed.