In a design review tool, people defer to each other's judgment. People are numbered 0 to n - 1, and defers[i] = [a, b] means person a defers to person b.
The final approver is the one person whom everybody else defers to, and who defers to nobody. Write findApprover(n, defers) that returns that person's number, or -1 if no such person exists.
No pair appears twice and nobody defers to themselves. With n = 1 and no pairs, person 0 is the final approver.
Input: n = 3, defers = [[0,2],[1,2]] Output: 2
Persons 0 and 1 both defer to 2, and 2 defers to nobody.
Input: n = 3, defers = [[0,2],[1,2],[2,0]] Output: -1
Person 2 defers to 0, so 2 is not the final approver, and nobody else is deferred to by everyone.
1 <= n <= 10^50 <= defers.length <= 2 * 10^50 <= a, b < n 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 #407 Find the Final Approver. 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.