FastPrepCount Paired Subarrays Reaching a Target

Count Paired Subarrays Reaching a Target

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

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) → long

Examples

Example 1

first = [1,2]second = [1,1]target = 3return = 3

First-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 = 1

The two singleton subarrays form one choice.

Constraints

  • 1 <= first.length,second.length <= 1000
  • 1 <= value <= 1000
  • 1 <= target <= 1000000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public long countPairedSubarrays(int[] first, int[] second, int target) {
    // Write your code here.
}
first[1,2]
second[1,1]
target3
expected3
Checking account…