Pattern · Depth-First Search

Depth-First Search interview questions

200 depth-first search problems tagged across recent interview reports. Drilled most heavily by linkedin, meta, and doordash.

Founder's read

Depth-First Search is the foundational graph and tree traversal pattern that powers 200+ interview problems. It's the backbone of connectivity questions, pathfinding, and tree manipulation, the kind of problem that appears across every major tech company assessment. LinkedIn, Meta, and DoorDash lean on DFS variants constantly. If you can't recognize and code DFS cold under pressure, you'll stall on live assessments. StealthCoder is the invisible safety net for the DFS variant that breaks your instinct during the real OA.

Most-asked depth-first search problems

#ProblemDiff# Companies
01Course ScheduleMEDIUM34
02Course Schedule IIMEDIUM33
03Binary Tree Maximum Path SumHARD27
04Clone GraphMEDIUM14
05Alien DictionaryHARD13
06Binary Tree Right Side ViewMEDIUM13
07All Nodes Distance K in Binary TreeMEDIUM10
08Binary Tree CamerasHARD9
09Cheapest Flights Within K StopsMEDIUM9
10Accounts MergeMEDIUM8
11Amount of Time for Binary Tree to Be InfectedMEDIUM8
12Design Add and Search Words Data StructureMEDIUM8
13Balanced Binary TreeEASY7
14Binary Tree Inorder TraversalEASY7
15Boundary of Binary TreeMEDIUM7
16Binary Tree Vertical Order TraversalMEDIUM4
17Binary Search Tree to Greater Sum TreeMEDIUM3
18Binary Tree PathsEASY3
19Count Sub IslandsMEDIUM3
20Battleships in a BoardMEDIUM2
21Binary Tree Longest Consecutive SequenceMEDIUM2
22Binary Tree Preorder TraversalEASY2
23Closest Binary Search Tree ValueEASY2
24Closest Binary Search Tree Value IIHARD2
25Closest Leaf in a Binary TreeMEDIUM2
26Concatenated WordsHARD2
27Convert Binary Search Tree to Sorted Doubly Linked ListMEDIUM2
28Count Good Nodes in Binary TreeMEDIUM2
29Count Nodes Equal to Average of SubtreeMEDIUM2
30Count Nodes With the Highest ScoreMEDIUM2
31Count Pairs of Connectable Servers in a Weighted Tree NetworkMEDIUM2
32All Ancestors of a Node in a Directed Acyclic GraphMEDIUM1
33All Paths From Source to TargetMEDIUM1
34Apply SubstitutionsMEDIUM1
35Binary Tree Postorder TraversalEASY1
36Binary Tree PruningMEDIUM1
37Binary Tree TiltEASY1
38Binary Tree Upside DownMEDIUM1
39Check if There is a Valid Path in a GridMEDIUM1
40Choose Edges to Maximize Score in a TreeMEDIUM1
41Coloring A BorderMEDIUM1
42Count Paths That Can Form a Palindrome in a TreeHARD1
43Count Univalue SubtreesMEDIUM1
44Count Unreachable Pairs of Nodes in an Undirected GraphMEDIUM1
45Count Valid Paths in a TreeHARD1
46Couples Holding HandsHARD1
47Cousins in Binary TreeEASY1
48Create Components With Same ValueHARD1
49Critical Connections in a NetworkHARD1
50Deepest Leaves SumMEDIUM1

Showing top 50 of 200 depth-first search problems by # companies asking.

The hedge for the live OA

You can't drill every depth-first search variant before the assessment. StealthCoder runs invisibly during screen share and solves whichever variant they throw at you. No browser extension. No detection signature. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

DFS problems fall into three buckets: graph connectivity (accounts-merge, all-ancestors-of-a-node-in-a-directed-acyclic-graph), tree traversal (balanced-binary-tree, binary-tree-inorder-traversal), and path-finding (all-paths-from-source-to-target). Recognize DFS by the need to explore every branch from a node before backtracking, either recursively via the call stack or iteratively with an explicit stack. Common subtypes include implicit graphs (grid-based like battleships-in-a-board), DAG problems, and tree annotation (binary-search-tree-to-greater-sum-tree). Start with tree DFS, move to grid and graph problems, then tackle the harder constraint variants. When you hit a hard DFS mutation in your live interview, especially under time pressure, StealthCoder reads the problem and delivers a working solution in seconds.

Companies that hire most on depth-first search

The honest play

200 depth-first search problems. You won't drill them all. Pass anyway.

Depth-First Search is one of the patterns interviews actually filter on. Memorizing every variant in a week is a fantasy. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds, no matter which depth-first search flavor lands in your live OA. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Depth-First Search interview FAQ

How many DFS problems should I drill before my OA?+

With 200 problems in this pattern, focus on the first 30 to 40 problems covering trees and grids. Practice recursive and iterative versions. Then drill 10 to 15 harder variants from your target company's list. Most candidates underestimate DFS subtlety; one hard problem during the real OA will break you if you haven't seen the pattern type.

Is DFS tested more heavily at certain companies?+

Yes. LinkedIn (76 problems), Meta (68), and DoorDash (60) weight DFS heavily in their assessments. If you're interviewing there, DFS fluency isn't optional, it's the minimum bar. Apple (38), Amazon (42), and Google (45) test it consistently, but breadth is also required.

How do I recognize a DFS problem in the wild?+

Look for explicit or implicit graphs, trees, or grids where you need to explore exhaustively. Keywords: 'all paths', 'connected components', 'reach', 'ancestors', 'traverse', 'merge', 'find all'. If the problem asks 'visit every node' or 'is X reachable from Y', DFS is likely the core pattern.

What's the difference between DFS and BFS in interviews?+

DFS uses a stack (recursion or explicit); BFS uses a queue. DFS is simpler to code and goes deep first, better for pathfinding, connectivity, and backtracking. BFS finds shortest paths in unweighted graphs. For most interview problems, DFS is the default unless the problem explicitly asks for 'shortest' or 'closest'.

Should I memorize the DFS template?+

Yes. A clean recursive DFS template, base case, mark visited, iterate neighbors, recurse, takes 15 seconds to write and removes cognitive load during the interview. Practice it until you can code it with your eyes closed. That mental space matters when a variant lands and you need to adapt.

Problem and frequency data sourced from public community-maintained interview-report repos. Problems and trademarks © LeetCode.