FastPrep4Sum II Tuple Count
Problems/4Sum II Tuple Count

4Sum II Tuple Count

SambaNova Systems logoSambaNova Systems● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand SambaNova five-round onsite report dated June 30, 2022 describes the well-known 4Sum II problem as one of the algorithm rounds. Our version is about 92% the same as the reported question.

Given four integer arrays, count index tuples (i, j, k, l) such that nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0.

Equal values at different indices represent different tuples. Return the count as a 64-bit integer.

Function

fourSumCount(nums1: int[], nums2: int[], nums3: int[], nums4: int[]) → long

Examples

Example 1

nums1 = [1,2]nums2 = [-2,-1]nums3 = [-1,2]nums4 = [0,2]return = 2

There are two complementary pair combinations.

Example 2

nums1 = [0]nums2 = [0]nums3 = [0]nums4 = [0]return = 1

The single tuple sums to zero.

Example 3

nums1 = [1,1]nums2 = [-1]nums3 = [0]nums4 = [0]return = 2

The equal ones occur at two distinct indices.

Constraints

  • 1 <= nums1.length, nums2.length, nums3.length, nums4.length <= 500.
  • -10^9 <= numsX[i] <= 10^9.
  • The returned count fits in a signed 64-bit integer.

More SambaNova Systems Onsite Interview questions

  • Vectorized K-Means AssignmentsONSITE INTERVIEW · Seen Apr 2024
  • Bomb Enemy Best CoordinatesONSITE INTERVIEW · Seen Jun 2022
  • Sum Nodes with an Even-Valued GrandparentONSITE INTERVIEW · Seen Jun 2022
  • Validate Binary Search TreeONSITE INTERVIEW · Seen Jun 2022
  • Deterministic Zigzag SortPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Maximum Area of IslandONSITE INTERVIEW · Seen Jun 2022
  • Task Scheduler with CooldownPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Point Inside a TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Parse Variable, Expression, and Application TreesPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2022
  • Flip Equivalent Binary TreesONSITE INTERVIEW · Seen Oct 2021

Similar questions at other companies

  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Shortest Uncommon SubstringAirbnb · ONSITE INTERVIEWAirbnb interview questions
  • Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Subarray Sum Equals KServiceNow · ONSITE INTERVIEWServiceNow interview questions
  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
  • Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Deep Copy a Random-Pointer ListAmazon · ONSITE INTERVIEW
  • Count Subarrays with Equal Even and Odd CountsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
All SambaNova Systems interview questionsSee SambaNova Systems hiring insights
Saved
class Solution {
    public long fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        // write your code here
    }
}
Checking account…