Mutual follows
Write code · Medium · §4.2 Pairs as keys
You are given the follow records follows. [a, b] means that a follows b. When two people follow each other, it is called a mutual follow.
Complete the function solution, which returns the number of mutual-follow pairs. The same record does not appear twice, and there is no record of a person following themselves.
Function
solution(follows)
Constraints
- The length of
followsis from 1 to 100,000. - Each person is identified by an integer from 0 to 1,000,000, and
aandbin one record are different.
Examples
| follows | result |
|---|---|
[[1, 2], [2, 1], [1, 3]] | 1 |
[[1, 2], [2, 3], [3, 1]] | 0 |
Starter code
def solution(follows):
answer = 0
return answerSolve 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.