Leetcode 323. Number of Connected Components in an Undirected Graph
Given n labeled nodes and a list of undirected edges, determine how many connected components the graph contains. This requires grouping nodes reachable from each other (e.g., via DFS/BFS or Union-Find) and counting the distinct groups.
Asked at:
Uber
Amazon
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Mid April, 2026
Uber
Junior
You are given a list of pairs, where each pair [a, b] indicates that person a and person b are friends. Friendship is bidirectional (if a is a friend of b, then b is also a friend of a) and transitive (if a is a friend of b, and b is a friend of c, then a is also indirectly a friend of c). A friend group is defined as a set of people who are directly or indirectly connected through friendships. Your task is to determine the total number of distinct friend groups.
Early June, 2025
Amazon
Senior
Hello Interview Premium
Your account is free and you can post anonymously if you choose.