Created
March 25, 2022 00:51
-
-
Save ibeauregard/a4a8bceaf85d63d2a31dce45eeaf2c1e to your computer and use it in GitHub Desktop.
Given k integer lists all of equal length, return the number of tuples (index[i] for 0 <= i < k) such that sum(arrays[i][index[i]] for 0 <= i < k) == 0.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
from itertools import product | |
class Solution: | |
def fourSumCount(self, *lists): | |
k = len(lists) | |
sum_to_count = Counter(sum(nums) for nums in product(*lists[:k // 2])) | |
return sum(sum_to_count[-sum(nums)] for nums in product(*lists[k // 2:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment