Medium Graph Problem

Problem A representative medium-difficulty graph task: given an undirected graph (or grid), compute connectivity — for example, count the connected components, or decide whether a path exists between two given nodes.

Input / Output

  • Input: n nodes and an edge list (or adjacency list / grid).
  • Output: the component count, or a reachability boolean, depending on the variant.

Constraints

  • Up to 10^5 nodes/edges; O(V + E) expected.

Example

  • n = 5, edges [[0,1],[1,2],[3,4]] → 2 components; path(0, 2) → true; path(0, 3) → false.
asked …
LeaderboardSalaryAccount