โ Back to Arrays
Question 397
Count Pairs Summing to a Target
Count Pairs Summing to a Target
The array{1, 5, 7, -1, 5}is given. Read a target integer from standard input, then count how many index pairs(i, j)withi < jsatisfyarr[i] + arr[j] == target, and print that count. For example, if the input is6, print: 3 The pairs summing to6are(1,5),(1,5), and(7,-1). Each unordered pair of positions is counted once.
Expected Output:
3
Topics:
Arrays
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.