4Sum II Tuple Count
Problem statement
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[]) → longExamples
Example 1
nums1 = [1,2]nums2 = [-2,-1]nums3 = [-1,2]nums4 = [0,2]return = 2There are two complementary pair combinations.
Example 2
nums1 = [0]nums2 = [0]nums3 = [0]nums4 = [0]return = 1The single tuple sums to zero.
Example 3
nums1 = [1,1]nums2 = [-1]nums3 = [0]nums4 = [0]return = 2The 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.