Largest Study Group - Problem
In a university, there are n students numbered 0 to n - 1. Some students are friends.
You are given a 2D array friendships where friendships[i] = [u, v] means students u and v are friends. Friendship is transitive.
Return the size of the largest study group.
Input & Output
Example 1
$
Input:
n=7, friendships=[[0,1],[0,2],[1,3],[4,5],[5,6]]
›
Output:
4
💡 Note:
Group {0,1,2,3}=4, Group {4,5,6}=3. Largest=4.
Example 2
$
Input:
n=4, friendships=[[0,1],[1,2],[2,3]]
›
Output:
4
💡 Note:
All connected.
Example 3
$
Input:
n=5, friendships=[]
›
Output:
1
💡 Note:
Each alone.
Constraints
- 1 ≤ n ≤ 2×10^5
- 0 ≤ friendships.length ≤ 2×10^5
- 0 ≤ u, v < n
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code