leetle

Daily challenge for 2025-09-24

267. Number of Connected Components

You have a graph of n nodes labeled from 0 to n - 1. You are given an integer n and a list of edges where edges[i] = [a, b] indicates that there is an undirected edge between nodes a and b in the graph. Return the number of connected components in the graph.

Example:
Input: n = 5, edges = [[0,1],[1,2],[3,4]]
Output: 2

Components: {0,1,2} and {3,4}

Run this challenge interactively in Python or JavaScript when the app loads.