Given a list of integers nums and an integer target, return how many pairs of positions i < j have nums[i] + nums[j] == target.
Pairs are counted by position, so equal values at different positions count separately.
The starter code checks every pair. Make it fast.
Example 1
Input:
count_pairs_with_sum([1, 2, 3, 4, 3], 6)
Output:
2
Positions (1, 3) give 2 + 4 and positions (2, 4) give 3 + 3.
Example 2
Input:
count_pairs_with_sum([2, 2, 2], 4)
Output:
3
All three pairs of positions sum to 4.
0 <= len(nums) <= 2 * 10**5-10**9 <= nums[i], target <= 10**910**10.No results yet
Run your code to check it against the examples, or submit to run every test.