Count Pairs with Sum
Medium 40 XPArraysHashing
Commonly asked at Amazon, Zoho
Read a list of integers and a target. Print how many pairs of positions (i < j) have values that add up to the target.
- Input
- Line 1: integers. Line 2: target.
- Output
- Number of pairs.
Sample 1
Input
1 5 7 -1 5 6
Output
3
Explanation: (1,5), (7,-1), (1,5)
Read input with input() (no prompt message) and print only the answer. Run tries the Input box; Submit checks all test cases.
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.The solution unlocks after 3 submissions.