Dynamic Programming, Recursion, Competitive Programming, Leetcode, 3sum.
not in two_sum_dict: two_sum_dict[arr[i] + arr[j]] = [(arr[i], arr[j])] else: two_sum_dict[arr[i] + arr[j]].append((arr[i], arr[j])) return two_sum_dict def three_sum(arr: list[int], sum: int) -> list[int]: if len(arr) < 3: return [] # Compute 3sum for the first part. c1 = three_sum(arr[:-1], sum)