Search
⌘K

Leetcode 2316. Count Unreachable Pairs of Nodes in an Undirected Graph

Given an undirected graph, count the number of unordered node pairs that are unreachable from each other — equivalently, pairs that lie in different connected components. Compute sizes of connected components and use combinatorics (sum of products of component sizes) in O(n + m) time (e.g., via DFS/BFS or Union-Find) to handle up to 1e5 nodes/edges.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Your account is free and you can post anonymously if you choose.