A profile page shows a "mutuals" badge when two users follow each other. You get the follow list follows, where [a, b] means user a follows user b.
Write countMutuals(follows) that returns how many unordered pairs of users follow each other. The pair {a, b} counts once, no matter the order of the two follows.
No follow appears twice and nobody follows themselves.
Input: follows = [[0,1],[1,0],[1,2],[2,3],[3,2]] Output: 2
Users 0 and 1 follow each other, and so do 2 and 3. The follow from 1 to 2 is one way.
Input: follows = [[0,1],[1,2]] Output: 0
No follow goes back the other way.
0 <= follows.length <= 1000000 <= a, b <= 10^9 and a !== bRun tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #406 Count Mutual Follows. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.