FastPrepCount Cross-Array Target-Sum Pairs
Problems/Count Cross-Array Target-Sum Pairs

Count Cross-Array Target-Sum Pairs

Visa logoVisa● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report gives two arrays, a target, and a count of pairs across the arrays whose values add up to the target. Our version makes clear how repeated index pairs count, the number size, the examples, and the limits.

You are given two integer arrays, first and second, and a signed 64-bit integer target.

Return the number of index pairs (i, j) such that first[i] + second[j] = target. Equal values at different indices are distinct occurrences and contribute separately. Compute each sum and the final count in signed 64-bit arithmetic.

Function

countCrossArrayTargetSumPairs(first: int[], second: int[], target: long) → long

Examples

Example 1

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

The two occurrences of 1 each pair with 3, and the single 2 pairs with both occurrences of 2.

Example 2

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

No cross-array pair exists when either array is empty.

Example 3

first = [-2,0,2]second = [2,0,-2,2]target = 0return = 4

The value -2 pairs with both 2 occurrences, while 0 pairs with 0 and 2 pairs with -2.

Constraints

  • 0 <= first.length, second.length <= 200000.
  • Every array value is a signed 32-bit integer.
  • target is a signed 64-bit integer.
  • The answer fits a signed 64-bit integer.

More Visa Online Assessment questions

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Lock CodeOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
  • Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
  • Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
  • Count Valid Space-Delimited WordsOA · Seen Oct 2026
  • Earliest Common Meeting StartOA · Seen Oct 2026
  • Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
  • Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026

Similar questions at other companies

  • Efficient TeamsExpedia · OAExpedia interview questions
  • Two SumMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Disjoint Target-Sum TripletsAmerican Express · PHONE SCREENAmerican Express interview questions
  • Macaron Order with Set DiscountsShopify · OAShopify interview questions
  • Build the Task HierarchyPendo · OA
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
  • Meandering ArrayVerisk · OA
  • Minimum Magic Stones After MergesElevenLabs · OAElevenLabs interview questions
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public long countCrossArrayTargetSumPairs(int[] first, int[] second, long target) {
      // write your code here
    }
}
Checking account…