Code RoomTwo-list sum pairs
MediumPrep Room Coding #4511

Two-list sum pairs

CodingAlgorithms & data structuresEntry–Mid~14 min

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.

Implement
cross_pair_count(a: list[int], b: list[int], target: int) → int
Examples
in[[1,2,2],[3,2],4]out3
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 14 min
InputExpectedGot
[[1,2,2],[3,2],4]3not run yetsample