Exercises/#125 Number of Connected Components
#125

Number of Connected Components

MediumπŸ•ΈοΈ Graphs
85 XP

Problem

Given n nodes and a list of undirected edges, return the number of connected components.

Examples

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

Input: n=5, edges=[[0,1],[1,2],[2,3],[3,4]]
Output: 1
graphunion-finddfs
AI Assistantβ€” powered by AI

Unlock hints progressively β€” start gentle, go deeper only if needed.

πŸ’‘

Level 1: Gentle Nudge

A subtle direction

πŸ—ΊοΈ

Level 2: Approach

The algorithm to use

πŸ”

Level 3: Detailed

Step-by-step guidance

125 / 150

Your Solution

⚑ JavaScript

to save progress and use AI features