A social app shows two numbers on every profile: how many people the user follows, and how many people follow them. Users are numbered from 0 to n - 1, and follows[i] = [a, b] means user a follows user b.
Write followCounts(n, follows) that returns an array with one entry per user, in user order. Entry i is [following, followers]: how many users i follows, and how many users follow i.
No pair appears twice, and nobody follows themselves.
Input: n = 4, follows = [[0,1],[0,2],[1,2],[3,0]] Output: [[2,1],[1,1],[0,2],[1,0]]
User 0 follows 1 and 2, and only user 3 follows user 0, so entry 0 is [2, 1].
Input: n = 3, follows = [] Output: [[0,0],[0,0],[0,0]]
Nobody follows anyone yet.
1 <= n <= 100000 <= follows.length <= 500000 <= a, b < n and a !== bRun tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #403 Follow Counts for Every User. 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.