Largest connected component

Write codeMedium25 min

Your task

Given an undirected graph with n nodes (0..n-1) and an edge list, return the size of the largest connected component (the number of nodes in it). The graph may be disconnected and may contain isolated nodes. If n is 0, return 0. Duplicate edges may appear.

Examples

largest_component_size(n: int, edges: list[list[int]]) -> int
Example 1
Inputlargest_component_size(6, [[0, 1], [1, 2], [3, 4]])
Output3