Sensor pair sum count

Write codeMedium14 min

Your task

Two calibration sensors each output a strictly increasing list of readings. A pairing test asks: how many ways can you pick one reading from sensor a and one from sensor b so that they add up exactly to target? Given a and b (each strictly increasing, no duplicates within a list) and the target, return the count. Walk a forward and b backward in one combined pass. Example: a = [1, 3, 5], b = [2, 4, 6], target = 7 gives 3 (1+6, 3+4, 5+2).

Examples

count_matching_pairs(a: list[int], b: list[int], target: int) -> int
Example 1
Inputcount_matching_pairs([1, 3, 5], [2, 4, 6], 7)
Output3