FunctionRacerProblemsRace

Mutual Follows

EasyGraphsPython, JavaScript, TypeScript, Java, C++

follows[i] is the list of accounts that account i follows. Accounts are numbered 0 to len(follows) - 1. Two different accounts a and b are mutual when a follows b and b follows a.

Return the number of mutual pairs. Each pair of accounts is counted once, no matter how many times the accounts appear in each other's lists. An account may follow itself; that never makes a mutual pair.

Example 1

follows [[1,2],[0],[0,1]]
returns 2

0 and 1 follow each other, and so do 0 and 2. Account 2 follows 1 but 1 does not follow 2 back.

Example 2

follows [[1],[2],[0]]
returns 0

The follows go around in a circle, so nobody is followed back.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Graphs problems