Problem. Given nums and k, return the length of the longest contiguous subarray whose sum is exactly k
(0 if none).
nums = [1, 2, 1, 1, 1], k = 3 → 3 ([1, 1, 1])
nums = [1, -1, 5, -2, 3], k = 3 → 4 ([1, -1, 5, -2])
nums = [-2, -1, 2, 1], k = 1 → 2 ([-1, 2])
ML context. "The longest stretch that nets to a target" is the longest balanced window when labels are coded as ±1 (k = 0): the longest period with as many positive as negative predictions, or as many clicks as non-clicks. It also answers "the longest window of a budget log that spends exactly B".
This is lesson 2.8 with a different question (longest, not count), and that changes what the hash map stores.