Skip to content

DFS Problems

Depth-first search explores as far as possible along each branch before backtracking. These problems use DFS on trees, graphs, and matrices — from simple traversals to complex path-finding and cycle detection.

52 problems

Title Difficulty
Alien Dictionary Hard
All Nodes Distance K in Binary Tree Medium
Balanced Binary Tree Easy
Binary Search Tree Iterator Medium
Binary Tree Cameras Hard
Binary Tree Maximum Path Sum Hard
Binary Tree Paths Easy
BST with a Dead End Easy
Course Schedule Medium
Is Graph Bipartite? Medium
Construct Binary Tree from Preorder and Postorder Traversal Medium
Construct BST from Preorder Traversal Hard
Convert Sorted Array to Binary Search Tree Easy
Count BST Nodes in a Range Medium
Critical Connections in a Network Hard
Depth-First Search of a Graph Easy
Detect Cycle in a Directed Graph Easy
Diameter of Binary Tree Easy
Evaluate Division Medium
Find Eventual Safe States Medium
Median of a Binary Search Tree Hard
Flatten Binary Tree to Linked List Medium
Flood Fill Easy
Capture Surrounded Regions Medium
Binary Tree Inorder Traversal Easy
Binary Tree to Doubly Linked List Hard
Invert Binary Tree Easy
Lowest Common Ancestor of a Binary Tree Medium
Making a Large Island Hard
Maximum Depth of Binary Tree Easy
Merge Two Binary Trees Easy
Distance Between Two Tree Nodes Medium
Minimum Absolute Difference in BST Easy
Number of Islands Medium
Path Sum Easy
Path Sum III Medium
All Downward Paths with Sum K Hard
Range Sum of BST Easy
All Paths Through a Maze Medium
Recover Binary Search Tree Medium
Same Tree Easy
Serialize and Deserialize Binary Tree Hard
Shortest Bridge Medium
Strongly Connected Components Medium
Subtree of Another Tree Easy
Sum of Left Leaves Easy
Symmetric Tree Easy
Time Needed to Inform All Employees Medium
Validate Binary Search Tree Medium
Vertical Order Traversal of a Binary Tree Hard
Word Search Medium
Word Search II Hard