Friend triangles

Write code · Medium · §7.2 Permutations and combinations

There are n users on a social network, numbered from 0 to n - 1. A record [a, b] in friends means that a and b are friends with each other, and either number may be written first. Three people who are all friends with one another form a friend triangle.

Complete the function solution, which returns the number of friend triangles. The same three people count only once, whatever order you pick them in.

Function

solution(n, friends)

Constraints

Examples

nfriendsresult
4[[0, 1], [1, 2], [0, 2], [2, 3]]1
5[[0, 1], [0, 2], [1, 2], [1, 3], [2, 3], [3, 4]]2

Starter code

def solution(n, friends):
    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.