A collaboration dashboard links people who have worked together. People are numbered 0 to n - 1, and pairs[i] = [a, b] means a and b have worked together. A team is a group of people connected through any chain of these pairs.
Write largestTeam(n, pairs) that returns the number of people in the largest team. A person with no pairs is a team of one.
Input: n = 6, pairs = [[0,1],[1,2],[3,4]] Output: 3
The teams are {0, 1, 2}, {3, 4}, and {5}. The largest has 3 people.
Input: n = 2, pairs = [] Output: 1
Two people who never worked together are two teams of one.
1 <= n <= 200000 <= pairs.length <= 1000000 <= 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 #418 Largest Connected Team. 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.