Skip to content
Use code for 50% offSee plans

Depth-First Search Problems

253 Depth-First Search LeetCode problems · Solve with AI-powered hints & step-by-step explanations.

Learn the coding interview patterns behind these problems, including Depth-First Search interview patterns.

Start with these

All Depth-First Search problems

79 Word Search Medium94 Binary Tree Inorder Traversal Easy98 Validate Binary Search Tree Medium99 Recover Binary Search Tree Medium100 Same Tree Easy101 Symmetric Tree Easy104 Maximum Depth of Binary Tree Easy110 Balanced Binary Tree Easy111 Minimum Depth of Binary Tree Easy112 Path Sum Easy113 Path Sum II Medium114 Flatten Binary Tree to Linked List Medium116 Populating Next Right Pointers in Each Node Medium117 Populating Next Right Pointers in Each Node II Medium124 Binary Tree Maximum Path Sum Hard129 Sum Root to Leaf Numbers Medium130 Surrounded Regions Medium133 Clone Graph Medium144 Binary Tree Preorder Traversal Easy145 Binary Tree Postorder Traversal Easy199 Binary Tree Right Side View Medium200 Number of Islands Medium207 Course Schedule Medium210 Course Schedule II Medium211 Design Add and Search Words Data Structure Medium226 Invert Binary Tree Easy230 Kth Smallest Element in a BST Medium235 Lowest Common Ancestor of a Binary Search Tree Medium236 Lowest Common Ancestor of a Binary Tree Medium257 Binary Tree Paths Easy297 Serialize and Deserialize Binary Tree Hard310 Minimum Height Trees Medium329 Longest Increasing Path in a Matrix Hard332 Reconstruct Itinerary Hard337 House Robber III Medium341 Flatten Nested List Iterator Medium365 Water and Jug Problem Medium385 Mini Parser Medium386 Lexicographical Numbers Medium388 Longest Absolute File Path Medium399 Evaluate Division Medium404 Sum of Left Leaves Easy417 Pacific Atlantic Water Flow Medium419 Battleships in a Board Medium430 Flatten a Multilevel Doubly Linked List Medium437 Path Sum III Medium449 Serialize and Deserialize BST Medium463 Island Perimeter Easy472 Concatenated Words Hard501 Find Mode in Binary Search Tree Easy508 Most Frequent Subtree Sum Medium513 Find Bottom Left Tree Value Medium514 Freedom Trail Hard515 Find Largest Value in Each Tree Row Medium529 Minesweeper Medium530 Minimum Absolute Difference in BST Easy538 Convert BST to Greater Tree Medium543 Diameter of Binary Tree Easy547 Number of Provinces Medium559 Maximum Depth of N-ary Tree Easy563 Binary Tree Tilt Easy565 Array Nesting Medium572 Subtree of Another Tree Easy589 N-ary Tree Preorder Traversal Easy590 N-ary Tree Postorder Traversal Easy606 Construct String from Binary Tree Medium617 Merge Two Binary Trees Easy623 Add One Row to Tree Medium637 Average of Levels in Binary Tree Easy652 Find Duplicate Subtrees Medium653 Two Sum IV - Input is a BST Easy655 Print Binary Tree Medium662 Maximum Width of Binary Tree Medium669 Trim a Binary Search Tree Medium671 Second Minimum Node In a Binary Tree Easy672 Bulb Switcher II Medium676 Implement Magic Dictionary Medium684 Redundant Connection Medium685 Redundant Connection II Hard687 Longest Univalue Path Medium690 Employee Importance Medium695 Max Area of Island Medium721 Accounts Merge Medium733 Flood Fill Easy743 Network Delay Time Medium749 Contain Virus Hard753 Cracking the Safe Hard756 Pyramid Transition Matrix Medium765 Couples Holding Hands Hard778 Swim in Rising Water Hard783 Minimum Distance Between BST Nodes Easy785 Is Graph Bipartite? Medium787 Cheapest Flights Within K Stops Medium797 All Paths From Source to Target Medium802 Find Eventual Safe States Medium814 Binary Tree Pruning Medium827 Making A Large Island Hard834 Sum of Distances in Tree Hard839 Similar String Groups Hard841 Keys and Rooms Medium851 Loud and Rich Medium863 All Nodes Distance K in Binary Tree Medium865 Smallest Subtree with all the Deepest Nodes Medium872 Leaf-Similar Trees Easy886 Possible Bipartition Medium897 Increasing Order Search Tree Easy924 Minimize Malware Spread Hard928 Minimize Malware Spread II Hard934 Shortest Bridge Medium938 Range Sum of BST Easy947 Most Stones Removed with Same Row or Column Medium951 Flip Equivalent Binary Trees Medium959 Regions Cut By Slashes Medium965 Univalued Binary Tree Easy968 Binary Tree Cameras Hard971 Flip Binary Tree To Match Preorder Traversal Medium979 Distribute Coins in Binary Tree Medium987 Vertical Order Traversal of a Binary Tree Hard988 Smallest String Starting From Leaf Medium993 Cousins in Binary Tree Easy1020 Number of Enclaves Medium1022 Sum of Root To Leaf Binary Numbers Easy1026 Maximum Difference Between Node and Ancestor Medium1028 Recover a Tree From Preorder Traversal Hard1034 Coloring A Border Medium1036 Escape a Large Maze Hard1038 Binary Search Tree to Greater Sum Tree Medium1042 Flower Planting With No Adjacent Medium1080 Insufficient Nodes in Root to Leaf Paths Medium1110 Delete Nodes And Return Forest Medium1123 Lowest Common Ancestor of Deepest Leaves Medium1145 Binary Tree Coloring Game Medium1161 Maximum Level Sum of a Binary Tree Medium1192 Critical Connections in a Network Hard1202 Smallest String With Swaps Medium1203 Sort Items by Groups Respecting Dependencies Hard1233 Remove Sub-Folders from the Filesystem Medium1254 Number of Closed Islands Medium1261 Find Elements in a Contaminated Binary Tree Medium1267 Count Servers that Communicate Medium1302 Deepest Leaves Sum Medium1305 All Elements in Two Binary Search Trees Medium1306 Jump Game III Medium1315 Sum of Nodes with Even-Valued Grandparent Medium1319 Number of Operations to Make Network Connected Medium1325 Delete Leaves With a Given Value Medium1339 Maximum Product of Splitted Binary Tree Medium1361 Validate Binary Tree Nodes Medium1367 Linked List in Binary Tree Medium1372 Longest ZigZag Path in a Binary Tree Medium1373 Maximum Sum BST in Binary Tree Hard1376 Time Needed to Inform All Employees Medium1377 Frog Position After T Seconds Hard1379 Find a Corresponding Node of a Binary Tree in a Clone of That Tree Easy1382 Balance a Binary Search Tree Medium1391 Check if There is a Valid Path in a Grid Medium1443 Minimum Time to Collect All Apples in a Tree Medium1448 Count Good Nodes in Binary Tree Medium1457 Pseudo-Palindromic Paths in a Binary Tree Medium1462 Course Schedule IV Medium1466 Reorder Routes to Make All Paths Lead to the City Zero Medium1483 Kth Ancestor of a Tree Node Hard1519 Number of Nodes in the Sub-Tree With the Same Label Medium1530 Number of Good Leaf Nodes Pairs Medium1559 Detect Cycles in 2D Grid Medium1568 Minimum Number of Days to Disconnect Island Hard1600 Throne Inheritance Medium1625 Lexicographically Smallest String After Applying Operations Medium1631 Path With Minimum Effort Medium1722 Minimize Hamming Distance After Swap Operations Medium1743 Restore the Array From Adjacent Pairs Medium1766 Tree of Coprimes Hard1905 Count Sub Islands Medium1932 Merge BSTs to Create Single BST Hard1938 Maximum Genetic Difference Query Hard1970 Last Day Where You Can Still Cross Hard1971 Find if Path Exists in Graph Easy1992 Find All Groups of Farmland Medium1993 Operations on Tree Medium2003 Smallest Missing Genetic Value in Each Subtree Hard2049 Count Nodes With the Highest Score Medium2092 Find All People With Secret Hard2096 Step-By-Step Directions From a Binary Tree Node to Another Medium2097 Valid Arrangement of Pairs Hard2101 Detonate the Maximum Bombs Medium2127 Maximum Employees to Be Invited to a Meeting Hard2192 All Ancestors of a Node in a Directed Acyclic Graph Medium2246 Longest Path With Different Adjacent Characters Hard2265 Count Nodes Equal to Average of Subtree Medium2316 Count Unreachable Pairs of Nodes in an Undirected Graph Medium2322 Minimum Score After Removals on a Tree Hard2328 Number of Increasing Paths in a Grid Hard2331 Evaluate Boolean Binary Tree Easy2359 Find Closest Node to Given Two Nodes Medium2360 Longest Cycle in a Graph Hard2368 Reachable Nodes With Restrictions Medium2385 Amount of Time for Binary Tree to Be Infected Medium2415 Reverse Odd Levels of Binary Tree Medium2440 Create Components With Same Value Hard2458 Height of Binary Tree After Subtree Removal Queries Hard2467 Most Profitable Path in a Tree Medium2476 Closest Nodes Queries in a Binary Search Tree Medium2477 Minimum Fuel Cost to Report to the Capital Medium2492 Minimum Score of a Path Between Two Cities Medium2493 Divide Nodes Into the Maximum Number of Groups Hard2538 Difference Between Maximum and Minimum Price Sum Hard2556 Disconnect Path in a Binary Matrix by at Most One Flip Medium2581 Count Number of Possible Root Nodes Hard2596 Check Knight Tour Configuration Medium2641 Cousins in Binary Tree II Medium2646 Minimize the Total Price of the Trips Hard2658 Maximum Number of Fish in a Grid Medium2685 Count the Number of Complete Components Medium2791 Count Paths That Can Form a Palindrome in a Tree Hard2858 Minimum Edge Reversals So Every Node Is Reachable Hard2867 Count Valid Paths in a Tree Hard2872 Maximum Number of K-Divisible Components Hard2920 Maximum Points After Collecting Coins From All Nodes Hard2925 Maximum Score After Applying Operations on a Tree Medium2973 Find Number of Coins to Place in Tree Nodes Hard3067 Count Pairs of Connectable Servers in a Weighted Tree Network Medium3123 Find Edges in Shortest Paths Hard3203 Find Minimum Diameter After Merging Two Trees Hard3235 Check if the Rectangle Corner Is Reachable Hard3241 Time Taken to Mark All Nodes Hard3249 Count the Number of Good Nodes Medium3310 Remove Methods From Project Medium3319 K-th Largest Perfect Subtree Size in Binary Tree Medium3327 Check if DFS Strings Are Palindromes Hard3331 Find Subtree Sizes After Changes Medium3367 Maximize Sum of Weights after Edge Removals Hard3372 Maximize the Number of Target Nodes After Connecting Trees I Medium3373 Maximize the Number of Target Nodes After Connecting Trees II Hard3376 Minimum Time to Break Locks I Medium3387 Maximize Amount After Two Days of Conversions Medium3419 Minimize the Maximum Edge Weight of Graph Medium3425 Longest Special Path Hard3486 Longest Special Path II Hard3493 Properties Graph Medium3515 Shortest Path in a Weighted Tree Hard3528 Unit Conversion I Medium3544 Subtree Inversion Sum Hard3547 Maximum Sum of Edge Values in a Graph Hard3553 Minimum Weighted Subgraph With the Required Paths II Hard3558 Number of Ways to Assign Edge Weights I Medium3559 Number of Ways to Assign Edge Weights II Hard3562 Maximum Profit from Trading Stocks with Discounts Hard3575 Maximum Good Subtree Score Hard3585 Find Weighted Median Node in Tree Hard3590 Kth Smallest Path XOR Sum Hard3593 Minimum Increments to Equalize Leaf Paths Medium3607 Power Grid Maintenance Medium3619 Count Islands With Total Value Divisible by K Medium