Two posts with a target sum

Write code · Basic · §7.1 Trying them all

views holds the number of views for each post. Complete the function solution, which returns the number of ways to pick two different posts whose views add up to target.

The order of picking does not matter. Even if two posts have the same number of views, they count as different posts.

Function

solution(views, target)

Constraints

Examples

viewstargetresult
[1, 2, 3, 4]52
[5, 5, 5]103

Starter code

def solution(views, target):
    answer = 0
    return answer

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.