Loading...
Loading...
Loading...
Count the pairs of positions i < j whose values add up to a target. Equal values at different positions are different pairs. The starter holds a program with a bug. Find it and fix it.
Example
Input
4 6 3 3 3 3
Output
6
Every two of the four threes make a pair: 6 pairs.
Try the problem first. Open one hint at a time.
Walk through the list and keep a count of every value seen before.
For each x, the pairs it completes equal the count of target - x so far.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor