Skip to content

Latest commit

 

History

History
13 lines (10 loc) · 409 Bytes

File metadata and controls

13 lines (10 loc) · 409 Bytes

Problem 8: The Connected Components (Number of Connected Components)

Problem Statement

Given n nodes labeled from 0 to n - 1 and a list of undirected edges, find the number of connected components in the graph.

Input Format

  • An integer n.
  • A list of edges edges.

Example

Input: n = 5, edges = [[0,1],[1,2],[3,4]]
Output: 2
Explanation: Components: {0,1,2} and {3,4}.