Count Paired Subarrays Reaching a Target
Problem statement
Given positive integer arrays first and second and a positive target, choose one nonempty contiguous subarray from each array.
Return the number of ordered choices whose two subarray sums add to target.
Function
countPairedSubarrays(first: int[], second: int[], target: int) → longExamples
Example 1
first = [1,2]second = [1,1]target = 3return = 3First-array sums 1 and 2 pair with second-array sums 2 and 1 respectively, producing three index-range choices.
Example 2
first = [5]second = [5]target = 10return = 1The two singleton subarrays form one choice.
Constraints
1 <= first.length,second.length <= 10001 <= value <= 10001 <= target <= 1000000