CJCoding With Joseph

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) with i < j satisfy arr[i] + arr[j] == target, and print that count.

For example, if the input is 6, print:

3

The pairs summing to 6 are (1,5), (1,5), and (7,-1). Each unordered pair of positions is counted once.

Expected Output:

3
Topics:
Arrays
๐Ÿ“ฅ Auto-Input:
6\n
This input is automatically fed to your program's stdin
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.