Return the length of the longest contiguous run of nums that adds up to exactly k, or 0 if none does. Unlike the earlier version of this question, nums can contain negative values.
The starter code tries every start and end. It is correct but too slow. Make it fast.
Example 1
Input:
longest_subarray_sum_k_any([1, -1, 5, -2, 3], 3)
Output:
4
The run [1, -1, 5, -2] adds to 3 and has length 4.
Example 2
Input:
longest_subarray_sum_k_any([2, 4, 6], 5)
Output:
0
No run adds to 5.
0 <= len(nums) <= 2 * 10**5-10**4 <= nums[i] <= 10**4-10**9 <= k <= 10**9No results yet
Run your code to check it against the examples, or submit to run every test.