Skip to the code
+10 XP

#418 Largest Connected Team

easy

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.

Example 1

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.

Example 2

Input: n = 2, pairs = []
Output: 1

Two people who never worked together are two teams of one.

Constraints

  • 1 <= n <= 20000
  • 0 <= pairs.length <= 100000
  • 0 <= a, b < n
Saved in this browser

Run 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).