# Depth-First Search DSA Problems

> 314 Depth-First Search coding problems for placements and interviews, sorted easiest first, with hints and company tags. Free practice on InternHack.

Canonical: https://www.internhack.in/learn/dsa/depth-first-search
Last updated: 2026-11-28

314 depth-first search problems for coding interviews and campus placements, with hints and company tags. Below are the first 100 of 314: 39 easy, 0 medium and 61 hard. Practise them free on InternHack and track what you have solved.

## Depth-First Search problems, easiest first

1. [Average of Levels in Binary Tree](https://www.internhack.in/learn/dsa/problem/average-of-levels-in-binary-tree) (Easy)
2. [Balanced Binary Tree](https://www.internhack.in/learn/dsa/problem/balanced-binary-tree) (Easy)
3. [Binary Tree Inorder Traversal](https://www.internhack.in/learn/dsa/problem/binary-tree-inorder-traversal) (Easy)
4. [Binary Tree Paths](https://www.internhack.in/learn/dsa/problem/binary-tree-paths) (Easy)
5. [Binary Tree Postorder Traversal](https://www.internhack.in/learn/dsa/problem/binary-tree-postorder-traversal) (Easy)
6. [Binary Tree Preorder Traversal](https://www.internhack.in/learn/dsa/problem/binary-tree-preorder-traversal) (Easy)
7. [Binary Tree Tilt](https://www.internhack.in/learn/dsa/problem/binary-tree-tilt) (Easy)
8. [Closest Binary Search Tree Value](https://www.internhack.in/learn/dsa/problem/closest-binary-search-tree-value) (Easy)
9. [Cousins in Binary Tree](https://www.internhack.in/learn/dsa/problem/cousins-in-binary-tree) (Easy)
10. [Diameter of Binary Tree](https://www.internhack.in/learn/dsa/problem/diameter-of-binary-tree) (Easy)
11. [Evaluate Boolean Binary Tree](https://www.internhack.in/learn/dsa/problem/evaluate-boolean-binary-tree) (Easy)
12. [Extract Kth Character From The Rope Tree](https://www.internhack.in/learn/dsa/problem/extract-kth-character-from-the-rope-tree) (Easy)
13. [Find a Corresponding Node of a Binary Tree in a Clone of That Tree](https://www.internhack.in/learn/dsa/problem/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree) (Easy)
14. [Find All The Lonely Nodes](https://www.internhack.in/learn/dsa/problem/find-all-the-lonely-nodes) (Easy)
15. [Find if Path Exists in Graph](https://www.internhack.in/learn/dsa/problem/find-if-path-exists-in-graph) (Easy)
16. [Find Mode in Binary Search Tree](https://www.internhack.in/learn/dsa/problem/find-mode-in-binary-search-tree) (Easy)
17. [Flood Fill](https://www.internhack.in/learn/dsa/problem/flood-fill) (Easy)
18. [Increasing Order Search Tree](https://www.internhack.in/learn/dsa/problem/increasing-order-search-tree) (Easy)
19. [Invert Binary Tree](https://www.internhack.in/learn/dsa/problem/invert-binary-tree) (Easy)
20. [Island Perimeter](https://www.internhack.in/learn/dsa/problem/island-perimeter) (Easy)
21. [Leaf-Similar Trees](https://www.internhack.in/learn/dsa/problem/leaf-similar-trees) (Easy)
22. [Maximum Depth of Binary Tree](https://www.internhack.in/learn/dsa/problem/maximum-depth-of-binary-tree) (Easy)
23. [Maximum Depth of N-ary Tree](https://www.internhack.in/learn/dsa/problem/maximum-depth-of-n-ary-tree) (Easy)
24. [Merge Two Binary Trees](https://www.internhack.in/learn/dsa/problem/merge-two-binary-trees) (Easy)
25. [Minimum Absolute Difference in BST](https://www.internhack.in/learn/dsa/problem/minimum-absolute-difference-in-bst) (Easy)
26. [Minimum Depth of Binary Tree](https://www.internhack.in/learn/dsa/problem/minimum-depth-of-binary-tree) (Easy)
27. [Minimum Distance Between BST Nodes](https://www.internhack.in/learn/dsa/problem/minimum-distance-between-bst-nodes) (Easy)
28. [N-ary Tree Postorder Traversal](https://www.internhack.in/learn/dsa/problem/n-ary-tree-postorder-traversal) (Easy)
29. [N-ary Tree Preorder Traversal](https://www.internhack.in/learn/dsa/problem/n-ary-tree-preorder-traversal) (Easy)
30. [Path Sum](https://www.internhack.in/learn/dsa/problem/path-sum) (Easy)
31. [Range Sum of BST](https://www.internhack.in/learn/dsa/problem/range-sum-of-bst) (Easy)
32. [Same Tree](https://www.internhack.in/learn/dsa/problem/same-tree) (Easy)
33. [Second Minimum Node In a Binary Tree](https://www.internhack.in/learn/dsa/problem/second-minimum-node-in-a-binary-tree) (Easy)
34. [Subtree of Another Tree](https://www.internhack.in/learn/dsa/problem/subtree-of-another-tree) (Easy)
35. [Sum of Left Leaves](https://www.internhack.in/learn/dsa/problem/sum-of-left-leaves) (Easy)
36. [Sum of Root To Leaf Binary Numbers](https://www.internhack.in/learn/dsa/problem/sum-of-root-to-leaf-binary-numbers) (Easy)
37. [Symmetric Tree](https://www.internhack.in/learn/dsa/problem/symmetric-tree) (Easy)
38. [Two Sum IV - Input is a BST](https://www.internhack.in/learn/dsa/problem/two-sum-iv-input-is-a-bst) (Easy)
39. [Univalued Binary Tree](https://www.internhack.in/learn/dsa/problem/univalued-binary-tree) (Easy)
40. [Alien Dictionary](https://www.internhack.in/learn/dsa/problem/alien-dictionary) (Hard)
41. [Binary Tree Cameras](https://www.internhack.in/learn/dsa/problem/binary-tree-cameras) (Hard)
42. [Binary Tree Maximum Path Sum](https://www.internhack.in/learn/dsa/problem/binary-tree-maximum-path-sum) (Hard)
43. [Check for Contradictions in Equations](https://www.internhack.in/learn/dsa/problem/check-for-contradictions-in-equations) (Hard)
44. [Check if DFS Strings Are Palindromes](https://www.internhack.in/learn/dsa/problem/check-if-dfs-strings-are-palindromes) (Hard)
45. [Check if the Rectangle Corner Is Reachable](https://www.internhack.in/learn/dsa/problem/check-if-the-rectangle-corner-is-reachable) (Hard)
46. [Checking Existence of Edge Length Limited Paths II](https://www.internhack.in/learn/dsa/problem/checking-existence-of-edge-length-limited-paths-ii) (Hard)
47. [Closest Binary Search Tree Value II](https://www.internhack.in/learn/dsa/problem/closest-binary-search-tree-value-ii) (Hard)
48. [Closest Node to Path in Tree](https://www.internhack.in/learn/dsa/problem/closest-node-to-path-in-tree) (Hard)
49. [Concatenated Words](https://www.internhack.in/learn/dsa/problem/concatenated-words) (Hard)
50. [Contain Virus](https://www.internhack.in/learn/dsa/problem/contain-virus) (Hard)
51. [Count Paths That Can Form a Palindrome in a Tree](https://www.internhack.in/learn/dsa/problem/count-paths-that-can-form-a-palindrome-in-a-tree) (Hard)
52. [Count Valid Paths in a Tree](https://www.internhack.in/learn/dsa/problem/count-valid-paths-in-a-tree) (Hard)
53. [Count Ways to Build Rooms in an Ant Colony](https://www.internhack.in/learn/dsa/problem/count-ways-to-build-rooms-in-an-ant-colony) (Hard)
54. [Couples Holding Hands](https://www.internhack.in/learn/dsa/problem/couples-holding-hands) (Hard)
55. [Cracking the Safe](https://www.internhack.in/learn/dsa/problem/cracking-the-safe) (Hard)
56. [Create Components With Same Value](https://www.internhack.in/learn/dsa/problem/create-components-with-same-value) (Hard)
57. [Critical Connections in a Network](https://www.internhack.in/learn/dsa/problem/critical-connections-in-a-network) (Hard)
58. [Design Search Autocomplete System](https://www.internhack.in/learn/dsa/problem/design-search-autocomplete-system) (Hard)
59. [Difference Between Maximum and Minimum Price Sum](https://www.internhack.in/learn/dsa/problem/difference-between-maximum-and-minimum-price-sum) (Hard)
60. [Distance to a Cycle in Undirected Graph](https://www.internhack.in/learn/dsa/problem/distance-to-a-cycle-in-undirected-graph) (Hard)
61. [Divide Nodes Into the Maximum Number of Groups](https://www.internhack.in/learn/dsa/problem/divide-nodes-into-the-maximum-number-of-groups) (Hard)
62. [Escape a Large Maze](https://www.internhack.in/learn/dsa/problem/escape-a-large-maze) (Hard)
63. [Find All People With Secret](https://www.internhack.in/learn/dsa/problem/find-all-people-with-secret) (Hard)
64. [Find Edges in Shortest Paths](https://www.internhack.in/learn/dsa/problem/find-edges-in-shortest-paths) (Hard)
65. [Find Minimum Diameter After Merging Two Trees](https://www.internhack.in/learn/dsa/problem/find-minimum-diameter-after-merging-two-trees) (Hard)
66. [Find Number of Coins to Place in Tree Nodes](https://www.internhack.in/learn/dsa/problem/find-number-of-coins-to-place-in-tree-nodes) (Hard)
67. [Find the Last Marked Nodes in Tree](https://www.internhack.in/learn/dsa/problem/find-the-last-marked-nodes-in-tree) (Hard)
68. [Find Weighted Median Node in Tree](https://www.internhack.in/learn/dsa/problem/find-weighted-median-node-in-tree) (Hard)
69. [Freedom Trail](https://www.internhack.in/learn/dsa/problem/freedom-trail) (Hard)
70. [Frog Position After T Seconds](https://www.internhack.in/learn/dsa/problem/frog-position-after-t-seconds) (Hard)
71. [Height of Binary Tree After Subtree Removal Queries](https://www.internhack.in/learn/dsa/problem/height-of-binary-tree-after-subtree-removal-queries) (Hard)
72. [Kth Ancestor of a Tree Node](https://www.internhack.in/learn/dsa/problem/kth-ancestor-of-a-tree-node) (Hard)
73. [Last Day Where You Can Still Cross](https://www.internhack.in/learn/dsa/problem/last-day-where-you-can-still-cross) (Hard)
74. [Longest Cycle in a Graph](https://www.internhack.in/learn/dsa/problem/longest-cycle-in-a-graph) (Hard)
75. [Longest Increasing Path in a Matrix](https://www.internhack.in/learn/dsa/problem/longest-increasing-path-in-a-matrix) (Hard)
76. [Longest Path With Different Adjacent Characters](https://www.internhack.in/learn/dsa/problem/longest-path-with-different-adjacent-characters) (Hard)
77. [Longest Special Path II](https://www.internhack.in/learn/dsa/problem/longest-special-path-ii) (Hard)
78. [Making A Large Island](https://www.internhack.in/learn/dsa/problem/making-a-large-island) (Hard)
79. [Maximize Sum of Weights after Edge Removals](https://www.internhack.in/learn/dsa/problem/maximize-sum-of-weights-after-edge-removals) (Hard)
80. [Maximize the Number of Target Nodes After Connecting Trees II](https://www.internhack.in/learn/dsa/problem/maximize-the-number-of-target-nodes-after-connecting-trees-ii) (Hard)
81. [Maximum Employees to Be Invited to a Meeting](https://www.internhack.in/learn/dsa/problem/maximum-employees-to-be-invited-to-a-meeting) (Hard)
82. [Maximum Genetic Difference Query](https://www.internhack.in/learn/dsa/problem/maximum-genetic-difference-query) (Hard)
83. [Maximum Good Subtree Score](https://www.internhack.in/learn/dsa/problem/maximum-good-subtree-score) (Hard)
84. [Maximum Number of K-Divisible Components](https://www.internhack.in/learn/dsa/problem/maximum-number-of-k-divisible-components) (Hard)
85. [Maximum Partition Factor](https://www.internhack.in/learn/dsa/problem/maximum-partition-factor) (Hard)
86. [Maximum Points After Collecting Coins From All Nodes](https://www.internhack.in/learn/dsa/problem/maximum-points-after-collecting-coins-from-all-nodes) (Hard)
87. [Maximum Profit from Trading Stocks with Discounts](https://www.internhack.in/learn/dsa/problem/maximum-profit-from-trading-stocks-with-discounts) (Hard)
88. [Maximum Subgraph Score in a Tree](https://www.internhack.in/learn/dsa/problem/maximum-subgraph-score-in-a-tree) (Hard)
89. [Maximum Sum BST in Binary Tree](https://www.internhack.in/learn/dsa/problem/maximum-sum-bst-in-binary-tree) (Hard)
90. [Maximum XOR of Two Non-Overlapping Subtrees](https://www.internhack.in/learn/dsa/problem/maximum-xor-of-two-non-overlapping-subtrees) (Hard)
91. [Merge BSTs to Create Single BST](https://www.internhack.in/learn/dsa/problem/merge-bsts-to-create-single-bst) (Hard)
92. [Minimize Malware Spread](https://www.internhack.in/learn/dsa/problem/minimize-malware-spread) (Hard)
93. [Minimize Malware Spread II](https://www.internhack.in/learn/dsa/problem/minimize-malware-spread-ii) (Hard)
94. [Minimum Edge Reversals So Every Node Is Reachable](https://www.internhack.in/learn/dsa/problem/minimum-edge-reversals-so-every-node-is-reachable) (Hard)
95. [Minimum Flips in Binary Tree to Get Result](https://www.internhack.in/learn/dsa/problem/minimum-flips-in-binary-tree-to-get-result) (Hard)
96. [Minimum Number of Days to Disconnect Island](https://www.internhack.in/learn/dsa/problem/minimum-number-of-days-to-disconnect-island) (Hard)
97. [Minimum Runes to Add to Cast Spell](https://www.internhack.in/learn/dsa/problem/minimum-runes-to-add-to-cast-spell) (Hard)
98. [Minimum Score After Removals on a Tree](https://www.internhack.in/learn/dsa/problem/minimum-score-after-removals-on-a-tree) (Hard)
99. [Minimum Time to Break Locks II](https://www.internhack.in/learn/dsa/problem/minimum-time-to-break-locks-ii) (Hard)
100. [Move Sub-Tree of N-Ary Tree](https://www.internhack.in/learn/dsa/problem/move-sub-tree-of-n-ary-tree) (Hard)

## Companies that ask depth-first search problems

- [Google](https://www.internhack.in/learn/dsa/companies/google): 74 of these problems
- [Amazon](https://www.internhack.in/learn/dsa/companies/amazon): 63 of these problems
- [Microsoft](https://www.internhack.in/learn/dsa/companies/microsoft): 44 of these problems
- [Meta](https://www.internhack.in/learn/dsa/companies/meta): 43 of these problems
- [Bloomberg](https://www.internhack.in/learn/dsa/companies/bloomberg): 34 of these problems
- [Uber](https://www.internhack.in/learn/dsa/companies/uber): 19 of these problems
- [Apple](https://www.internhack.in/learn/dsa/companies/apple): 14 of these problems
- [Oracle](https://www.internhack.in/learn/dsa/companies/oracle): 14 of these problems
- [Tiktok](https://www.internhack.in/learn/dsa/companies/tiktok): 12 of these problems
- [Linkedin](https://www.internhack.in/learn/dsa/companies/linkedin): 9 of these problems
- [Salesforce](https://www.internhack.in/learn/dsa/companies/salesforce): 6 of these problems
- [Adobe](https://www.internhack.in/learn/dsa/companies/adobe): 6 of these problems

## Before your interview

Most resumes are filtered by software before a recruiter reads them. [Check your resume ATS score free](https://www.internhack.in/ats-score/try), no signup needed.

## Other DSA topics

- [Array](https://www.internhack.in/learn/dsa/array) (1869)
- [String](https://www.internhack.in/learn/dsa/string) (775)
- [Hash Table](https://www.internhack.in/learn/dsa/hash-table) (708)
- [Math](https://www.internhack.in/learn/dsa/math) (564)
- [Dynamic Programming](https://www.internhack.in/learn/dsa/dynamic-programming) (557)
- [Sorting](https://www.internhack.in/learn/dsa/sorting) (464)
- [Greedy](https://www.internhack.in/learn/dsa/greedy) (407)
- [Binary Search](https://www.internhack.in/learn/dsa/binary-search) (298)
- [Matrix](https://www.internhack.in/learn/dsa/matrix) (246)
- [Breadth-First Search](https://www.internhack.in/learn/dsa/breadth-first-search) (245)
- [Bit Manipulation](https://www.internhack.in/learn/dsa/bit-manipulation) (238)
- [Tree](https://www.internhack.in/learn/dsa/tree) (235)
- [Two Pointers](https://www.internhack.in/learn/dsa/two-pointers) (217)
- [Prefix Sum](https://www.internhack.in/learn/dsa/prefix-sum) (204)
- [Database](https://www.internhack.in/learn/dsa/database) (197)
- [Heap (Priority Queue)](https://www.internhack.in/learn/dsa/heap-priority-queue) (196)
- [Simulation](https://www.internhack.in/learn/dsa/simulation) (177)
- [Counting](https://www.internhack.in/learn/dsa/counting) (174)
- [Binary Tree](https://www.internhack.in/learn/dsa/binary-tree) (169)
- [Stack](https://www.internhack.in/learn/dsa/stack) (167)

## Related

- [Home](https://www.internhack.in/)
- [Learn](https://www.internhack.in/learn)
- [DSA](https://www.internhack.in/learn/dsa)
