252. 4Sum II

MediumHash Table

Given four integer arrays `nums1`, `nums2`, `nums3`, and `nums4` all of length `n`, return the number of tuples `(i, j, k, l)` such that: - `0 <= i, j, k, l < n` - `nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0`

Examples

Input: [1,2] [-2,-1] [-1,2] [0,2]

Output: 2

Explanation: Two tuples sum to 0: (0,0,0,1)→1+(-2)+(-1)+2=0 and (1,1,0,0)→2+(-1)+(-1)+0=0.

Constraints

  • n == nums1.length == nums2.length == nums3.length == nums4.length
  • 1 <= n <= 200
  • -2^28 <= nums1[i], nums2[i], nums3[i], nums4[i] <= 2^28
Loading...

Run checks all cases above. Submit evaluates all test cases.