This question evaluates proficiency in array algorithms, cumulative-sum (prefix-sum) reasoning, and hash-based frequency techniques, including understanding how negative values affect subarray sums.
Given an integer array nums and an integer k, count the number of contiguous subarrays whose sum equals k. Solve it in O(n) time and O(n) space by maintaining a running prefix sum and a hash map of prefix-sum frequencies. Explain why this works with negative numbers, analyze complexity, and provide code or pseudocode.