3Sum With Multiplicity LeetCode solution in Python
1class Solution:2def threeSumMulti(self, arr: List[int], target: int) -> int:3arr.sort()4count = 05for i in range(0, len(arr) - 2):6rem_sum = target - arr[i]7hash_map = {}8for j in range(i + 1, len(arr)):9if arr[j] > rem_sum:10break11if rem_sum - arr[j] in hash_map:12count = count + hash_map[rem_sum - arr[j]]13# update the hash_map14hash_map[arr[j]] = hash_map.get(arr[j], 0) + 115return count % 1000000007