← All problems

Graph Valid Tree

Medium graphsunion-finddfs LeetCode ↗
Given n nodes and edges, determine if they form a valid tree.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n α(n)), Space O(n)

Common pitfalls

  • Only checking edge count
  • Self-loops not treated as cycles

Your solution

Log in to save your code and track progress.