Your question is Longest Subarray With Target Sum. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Given an integer array nums and an integer target, return the length of the longest continuous subarray whose elements sum to target. If no such subarray exists, return 0. The array may contain positive numbers, negative numbers, and zeros.
def longest_subarray_with_sum(nums, target):