Count Paired Subarrays Reaching a Target
Updated
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 = 3A first-array sum of 1 needs a second-array sum of 2, and a first-array sum of 2 needs a second-array sum of 1. The sum two in the second array comes from one subarray, and the sum one comes from two different subarrays. That makes one choice plus two choices, three in all.
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
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
Similar questions at other companies
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Count Zero-Sum FragmentsTesla · OATesla interview questions
- Count Stable Server SubsegmentsScale AI · OAScale AI interview questions
- Number of Unique Elements After Modifications 🍁Infosys · OAInfosys interview questions
- Count Subarrays with Sum KIndeed · OAIndeed interview questions
- Count Subarrays With Given XORInMobi · OAInMobi interview questions
- Count Subarrays with Sum Divisible by KVisa · OAVisa interview questions
- Beautiful SubarraysAtlassian · OAAtlassian interview questions
- Find Security LevelAmazon · OA
- Subarray Sum Equals KServiceNow · ONSITE INTERVIEWServiceNow interview questions