CJCoding With Joseph
15free / daySign inCreate account

Count Pairs That Sum

Write count_pairs(values: list[int], target: int) -> int that returns how many pairs of positions, with the first index before the second, hold two values adding up to target. Use two nested loops over range(len(values)) so every pair is tried exactly once, and keep a running count instead of returning early. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: two lines, a space-separated list of integers and then the target; the tests print the count your function returns.

Expected Output:

3

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
Data Structures & AlgorithmsBig-O
📥 Auto-Input:
1 5 7 -1 5\n6\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.