An org chart tool imports reporting lines from a spreadsheet. People are numbered 0 to n - 1, and each lines[i] = [a, b] is a reporting line between a and b (direction doesn't matter here).
The chart is valid only if the lines form a tree: everyone is connected, and there are no loops. Write isTree(n, lines) that returns true if they do and false otherwise.
Input: n = 4, lines = [[0,1],[0,2],[2,3]] Output: true
Everyone is connected through 3 lines, with no loop.
Input: n = 4, lines = [[0,1],[1,2],[2,0]] Output: false
0, 1, and 2 form a loop, and person 3 isn't connected at all.
1 <= n <= 10^50 <= lines.length <= 2 * 10^50 <= a, b < nRun 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 #448 Is the Org Chart a Tree?. 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.