Two-list sum pairs
Your task
You are given two integer lists a and b and a target integer. Count how many ordered index pairs (i, j) satisfy a[i] + b[j] == target, where i indexes into a and j indexes into b. Every index pair counts separately, even when values repeat. For example, with a = [1, 2, 2], b = [3, 2] and target 4, the pairs are (0,0), (1,1) and (2,1), so the answer is 3. Comparing every element of a with every element of b is too slow for large inputs, do better using a hash map.
Examples
cross_pair_count(a: list[int], b: list[int], target: int) -> intExample 1
Input
cross_pair_count([1, 2, 2], [3, 2], 4)Output
3