HomeDepth-First Search
Depth-First Search
Dive deep first — trees, recursion, and connectivity.
25 shown
- Maximum Depth of Binary Tree1 + max(left depth, right depth)animatedEasy
- Number of IslandsSink each connected blob of landanimatedMedium
- Clone GraphDFS with a visited→copy mapanimatedMedium
- Practice problems
- IntroductionGo deep first, back up when stuckanimatedMedium
- FundamentalsBase case, process, recurseanimatedMedium
- Return ValuesLet each call hand a fact upwardanimatedMedium
- Path SumSubtract as you descend, check at the leafMedium
- Passing Values Down and UpContext descends, results ascendanimatedMedium
- Validate Binary Search TreeCarry a valid range downwardanimatedMedium
- Binary Tree TiltReturn the subtree sum, accumulate the tiltMedium
- Diameter of a Binary TreeReturn the height, track the best bendanimatedMedium
- Path Sum IIThe same descent, recording every pathMedium
- Longest Univalue PathExtend only through equal valuesMedium
- Invert Binary TreeSwap the children, everywhereanimatedMedium
- Same TreeBoth null, or both equal with matching subtreesMedium
- Lowest Common Ancestor of a Binary TreeThe first node with a hit on both sidesanimatedMedium
- Binary Tree Maximum Path SumBend at most once, drop negative branchesanimatedMedium
- Serialize and Deserialize Binary TreePreorder with null markersMedium
- Graphs OverviewNodes and edges, and the four variationsanimatedMedium
- Adjacency ListEach node keeps a list of its neighboursanimatedMedium
- Copy GraphMap original nodes to their clonesanimatedMedium
- Graph Valid TreeConnected, and exactly V-1 edgesMedium
- MatricesA grid is a graph with implicit edgesanimatedMedium
- Flood FillRecolour the connected regionanimatedMedium
- Pacific Atlantic Water FlowSearch inland from both oceansMedium