Zero-Sum Picks From Four Lists
Pick one number from each of the four lists a, b, c and d. A pick is a choice of positions (i, j, k, l), so equal values at different positions give different picks.
Return how many picks satisfy a[i] + b[j] + c[k] + d[l] == 0.
Example 1
a [1,2]
b [-2,-1]
c [-1,2]
d [0,2]
returns 2
1 + (-2) + (-1) + 2 = 0 and 2 + (-1) + (-1) + 0 = 0; no other pick works.
Example 2
a [0]
b [0]
c [0]
d [0]
returns 1
The single pick of four zeros adds up to 0.
Constraints
1 <= len(a), len(b), len(c), len(d) <= 20-50 <= value <= 50for every value in the four lists
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.