Tree Depth-First Search (DFS)
Trees & GraphsRecursive top-down and bottom-up traversals on hierarchical structures
353 problems·42 Easy·224 Medium·87 Hard
Pattern Study Guide & Cheat Sheet▼
Traverse binary or general trees by recurring deep along branches, computing subtree metrics bottom-up (postorder) or passing state top-down (preorder).
Core Invariant: Recursive Trust: Assume `dfs(node.left)` and `dfs(node.right)` return the correct subtree answers. Combine them at `node` with the base case (`if not node: return base_val`).
Recognize it (Keywords & Signals)
- Maximum / minimum depth of binary tree
- Invert / clone binary tree
- Diameter of binary tree
- Lowest common ancestor (LCA)
- Path sum / maximum path sum across branches
- Check balanced binary tree
When NOT to use
Level-by-level processing or shortest path in terms of edge counts (Tree BFS is cleaner).
How to solve (Step-by-step)
- 1.Handle base case: `if not node: return 0` (or `None`, `True`).
- 2.Recursively solve left subtree: `left = dfs(node.left)`.
- 3.Recursively solve right subtree: `right = dfs(node.right)`.
- 4.Combine results at parent: e.g., update global variable `self.max_diameter = max(self.max_diameter, left + right)`.
- 5.Return single-branch contribution upward: `return 1 + max(left, right)`.
Watch for (Interview Traps)
- Mixing up what is returned upward vs what updates the global answer (e.g. returning both branches to parent)
- Recursion limit exceeded on deeply skewed trees (Python default limit is 1000)
- Forgetting to handle `node is None` as base case
Bottom-Up Postorder Tree DFS (Diameter / Path Metric)
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
def diameter_of_binary_tree(root: TreeNode | None) -> int:
max_diameter = 0
def dfs(node: TreeNode | None) -> int:
nonlocal max_diameter
if not node:
return 0 # Height of empty subtree
# Postorder: solve children first
left_height = dfs(node.left)
right_height = dfs(node.right)
# Invariant: longest path through current node spans both subtrees
max_diameter = max(max_diameter, left_height + right_height)
# Return single branch height upward to parent
return 1 + max(left_height, right_height)
dfs(root)
return max_diameter- Cost
- O(N) visits each node once · O(H) call stack where H is tree height (O(log N) balanced, O(N) worst-case skewed) (Avoids O(N^2) parent traversals.)
Canonical problems
#104 Maximum Depth of Binary Tree: 1 + max(dfs(left), dfs(right))
#226 Invert Binary Tree: Swap node.left and node.right recursively
#543 Diameter of Binary Tree: Combine left and right depths at each node
#236 Lowest Common Ancestor of a Binary Tree: Return node if target found in both subtrees
⌘K
Medium·25 companies·Max freq 100%·Acc 64.4%
Tower Research CapitalTower Research CapitalUrban Company+22
Hard·25 companies·Max freq 100%·Acc 61.1%
YahooHiveNeetCode 150+22
Medium·24 companies·Max freq 100%·Acc 69.7%
NewsBreakAirwallexMeta+21
Medium·23 companies·Max freq 88%·Acc 36.0%
WixNeetCode 150NeetCode 150+20
Medium·22 companies·Max freq 100%·Acc 42.2%
HTCMakeMyTripStripe+19
Easy·20 companies·Max freq 100%·Acc 78.4%
YahooNeetCode 150NeetCode 150+17
Hard·20 companies·Max freq 93%·Acc 56.8%
DoorDashWeRideDuolingo+17
Medium·19 companies·Max freq 100%·Acc 64.1%
SigmoidNutanixAdobe+16
Medium·18 companies·Max freq 100%·Acc 73.0%
GojekNeetCode 150NeetCode 150+15
#934Shortest Bridge
Medium·18 companies·Max freq 100%·Acc 59.6%
Tower Research CapitalMcKinseyTower Research Capital+15
Medium·17 companies·Max freq 100%·Acc 68.5%
Texas InstrumentsSpaceXGoldman Sachs+14
Medium·16 companies·Max freq 88%·Acc 48.7%
DatadogNeetCode 150NeetCode 150+13
Hard·15 companies·Max freq 100%·Acc 54.2%
SamsungRokuMeta+12
Medium·14 companies·Max freq 100%·Acc 61.2%
Urban CompanyServiceNowNeetCode 150+11
Medium·14 companies·Max freq 100%·Acc 70.9%
XXNeetCode 150+11
Medium·14 companies·Max freq 88%·Acc 77.0%
UberNeetCode 150NeetCode 150+11
Medium·13 companies·Max freq 100%·Acc 65.7%
blinkitShareChatServiceNow+10
Hard·13 companies·Max freq 75%·Acc 50.0%
RobloxPinterestMongoDB+10
Medium·12 companies·Max freq 83%·Acc 69.1%
NeetCode 150NeetCode 150TikTok+9
Medium·11 companies·Max freq 100%·Acc 66.9%
Akuna CapitalPhonePeIBM+8
Medium·11 companies·Max freq 89%·Acc 83.0%
MetaLinkedInMongoDB+8
Hard·11 companies·Max freq 88%·Acc 0.6%
KLA TencorInMobiAkuna Capital+8
Easy·11 companies·Max freq 87%·Acc 80.2%
NeetCode 150NeetCode 150Josh Technology+8
Hard·11 companies·Max freq 77%·Acc 60.0%
UberMathWorksMeesho+8
Medium·10 companies·Max freq 100%·Acc 66.9%
ZenefitsLyftSalesforce+7
Medium·10 companies·Max freq 100%·Acc 65.1%
XGeneral MotorsX+7
#113Path Sum II
Medium·10 companies·Max freq 63%·Acc 62.5%
Arista NetworksPalo Alto NetworksFlipkart+7
Medium·9 companies·Max freq 100%·Acc 75.1%
RobinhoodSIGCapital One+6
Medium·9 companies·Max freq 84%·Acc 73.9%
NeetCode 150NeetCode 150Josh Technology+6
Easy·9 companies·Max freq 75%·Acc 75.8%
AirbnbAccentureAmazon+6
Medium·8 companies·Max freq 88%·Acc 78.6%
VerkadaNuroSnowflake+5
Medium·8 companies·Max freq 64%·Acc 77.3%
Zeta GlobalGoldman Sachstcs+5
Medium·8 companies·Max freq 53%·Acc 67.4%
Walmart LabsBloombergMeta+5
Medium·8 companies·Max freq 52%·Acc 66.3%
Josh TechnologyLinkedInApple+5
Medium·7 companies·Max freq 100%·Acc 83.9%
ClariLinkedInUber+4
Medium·7 companies·Max freq 88%·Acc 72.4%
GopuffJosh TechnologyMicrosoft+4
Hard·7 companies·Max freq 88%·Acc 77.4%
Booking.comBooking.comNvidia+4
Medium·7 companies·Max freq 79%·Acc 63.1%
BloombergAdobeAmazon+4
Hard·7 companies·Max freq 63%·Acc 0.6%
CitadelSquarepoint CapitalPalo Alto Networks+4
Medium·7 companies·Max freq 63%·Acc 73.5%
AndurilMicrosoftAmazon+4
Medium·7 companies·Max freq 63%·Acc 69.1%
Walmart LabsMicrosoftTikTok+4
Medium·7 companies·Max freq 50%·Acc 57.8%
BloombergMetaMicrosoft+4
Medium·6 companies·Max freq 100%·Acc 51.2%
Pocket GemsDocusignMicrosoft+3
Hard·6 companies·Max freq 100%·Acc 0.5%
Hudson River TradingHudson River TradingTarget+3
Hard·6 companies·Max freq 100%·Acc 0.5%
thoughtspotWeRideUber+3
Medium·6 companies·Max freq 88%·Acc 56.5%
DatabricksSnowflakeTikTok+3
Hard·6 companies·Max freq 70%·Acc 83.3%
GrammarlyAmazonGoogle+3
Hard·6 companies·Max freq 63%·Acc 66.9%
UberAccentureGoogle+3
Medium·6 companies·Max freq 38%·Acc 84.4%
AmazonSalesforceMeta+3
Medium·6 companies·Max freq 25%·Acc 68.6%
OracleBloombergAmazon+3
Medium·6 companies·Max freq 25%·Acc 78.1%
AppleGoogleBloomberg+3
Medium·5 companies·Max freq 100%·Acc 51.8%
ZenefitsExpediaSalesforce+2
Medium·5 companies·Max freq 63%·Acc 78.2%
Josh TechnologyEPAM SystemsAmazon+2
Medium·5 companies·Max freq 63%·Acc 63.8%
CiscoPhonePeMeta+2
Medium·5 companies·Max freq 63%·Acc 83.7%
BloombergNetflixAmazon+2
Medium·5 companies·Max freq 63%·Acc 0.5%
SnapSnapAmazon+2
Hard·5 companies·Max freq 60%·Acc 61.8%
NutanixMicrosoftOracle+2
Hard·5 companies·Max freq 56%·Acc 66.0%
CitadelMetaAmazon+2
Medium·5 companies·Max freq 50%·Acc 66.0%
TikTokMicrosoftAmazon+2
Medium·5 companies·Max freq 38%·Acc 55.8%
MicrosoftAmazonGoogle+2
Medium·5 companies·Max freq 38%·Acc 65.4%
MicrosoftAmazonUber+2
Hard·4 companies·Max freq 100%·Acc 69.4%
Deutsche BankBlackRockMeta+1
Hard·4 companies·Max freq 100%·Acc 57.0%
ServiceNowOracleMicrosoft+1
Medium·4 companies·Max freq 88%·Acc 53.1%
JuspayAmazonBloomberg+1
Medium·4 companies·Max freq 79%·Acc 0.7%
Sumo LogicSumo LogicGoogle+1
Medium·4 companies·Max freq 67%·Acc 77.2%
Josh TechnologyAmazonMicrosoft+1
Medium·4 companies·Max freq 64%·Acc 65.6%
MetaTikTokAmazon+1
Medium·4 companies·Max freq 63%·Acc 86.0%
Josh TechnologySalesforceAmazon+1
Medium·4 companies·Max freq 63%·Acc 62.3%
OracleGoogleAmazon+1
Medium·4 companies·Max freq 63%·Acc 79.6%
AtlassianAmazonTikTok+1
Medium·4 companies·Max freq 53%·Acc 86.8%
MetaSnowflakeAmazon+1
Medium·4 companies·Max freq 51%·Acc 69.7%
LinkedInMetaAtlassian+1
Medium·4 companies·Max freq 50%·Acc 54.8%
TikTokGoogleMeta+1
Medium·4 companies·Max freq 39%·Acc 77.6%
MetaBloombergAmazon+1
Medium·4 companies·Max freq 38%·Acc 79.5%
MetaGoogleBloomberg+1
Hard·4 companies·Max freq 38%·Acc 74.0%
InfosysGoogleAmazon+1
Medium·4 companies·Max freq 28%·Acc 70.0%
GoogleMetaMicrosoft+1
Hard·4 companies·Max freq 25%·Acc 76.1%
AmazonMetaMicrosoft+1
Medium·4 companies·Max freq 16%·Acc 80.8%
MicrosoftMetaAmazon+1
Hard·3 companies·Max freq 100%·Acc 0.3%
GameskraftUberLinkedIn
Medium·3 companies·Max freq 100%·Acc 64.5%
RobinhoodSamsungGoogle
Medium·3 companies·Max freq 100%·Acc 56.2%
UBSthoughtspotRippling
Medium·3 companies·Max freq 100%·Acc 74.3%
GuidewireAmazonGoogle
Medium·3 companies·Max freq 60%·Acc 61.7%
RipplingUberGoogle
Hard·3 companies·Max freq 38%·Acc 54.9%
SnowflakeGoogleMeta
Medium·3 companies·Max freq 25%·Acc 50.1%
UberGoogleMeta
Hard·3 companies·Max freq 13%·Acc 72.5%
BloombergAmazonGoogle
Medium·2 companies·Max freq 100%·Acc 69.4%
JioGoogle
Hard·2 companies·Max freq 100%·Acc 73.1%
JioGoogle
Medium·2 companies·Max freq 88%·Acc 55.5%
SamsungUber
Medium·2 companies·Max freq 79%·Acc 56.2%
IntuitGoogle
Hard·2 companies·Max freq 75%·Acc 51.6%
Oscar HealthGoogle
Medium·2 companies·Max freq 25%·Acc 84.1%
GoogleAmazon
Medium·2 companies·Max freq 16%·Acc 41.4%
GoogleMicrosoft
Hard·2 companies·Max freq 13%·Acc 56.5%
MetaGoogle
Hard·1 companies·Max freq 90%·Acc 47.0%
Sprinklr
Hard·1 companies·Max freq 75%·Acc 36.9%
DE Shaw
Medium·1 companies·Max freq 28%·Acc 82.5%
Amazon
Easy·1 companies·Max freq 27%·Acc 85.9%
Meta
Hard·1 companies·Max freq 25%·Acc 62.9%
Amazon
Hard·1 companies·Max freq 25%·Acc 43.6%
Amazon
Medium·1 companies·Max freq 25%·Acc 28.0%
Google
Medium·1 companies·Max freq 25%·Acc 47.5%
Google
Medium·1 companies·Max freq 13%·Acc 62.4%
Google
# | Problem | Difficulty | Top Companies↓ | Frequency | Acceptance | |
|---|---|---|---|---|---|---|
| #200 | Number of Islands ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 100% | 64.7% | ||
| #207 | Course Schedule Depth-First SearchBreadth-First SearchGraph TheoryTopological SortDirected Acyclic Graph | Medium | 100% | 51.8% | ||
| #210 | Course Schedule II Depth-First SearchBreadth-First SearchGraph TheoryTopological Sort | Medium | 100% | 55.9% | ||
| #79 | Word Search ArrayStringBacktrackingDepth-First SearchMatrix | Medium | 100% | 47.7% | ||
| #124 | Binary Tree Maximum Path Sum Dynamic ProgrammingTreeDepth-First SearchBinary TreeDP on Trees | Hard | 100% | 42.5% | ||
| #332 | Reconstruct Itinerary ArrayStringDepth-First SearchGraph TheorySortingHeap (Priority Queue)Eulerian CircuitEulerian PathSemi-Eulerian Graph | Hard | 100% | 44.7% | ||
| #399 | Evaluate Division ArrayStringDepth-First SearchBreadth-First SearchUnion-FindGraph TheoryShortest PathBellman–Ford AlgorithmFloyd–Warshall Algorithm | Medium | 100% | 64.4% | ||
| #297 | Serialize and Deserialize Binary Tree StringTreeDepth-First SearchBreadth-First SearchDesignBinary Tree | Hard | 100% | 61.1% | ||
| #236 | Lowest Common Ancestor of a Binary Tree TreeDepth-First SearchBinary TreeBinary LiftingLowest Common Ancestor | Medium | 100% | 69.7% | ||
| #269 | Alien Dictionary ArrayStringDepth-First SearchBreadth-First SearchGraph TheoryTopological SortDirected Acyclic Graph | Hard | 100% | 37.3% | ||
| #543 | Diameter of Binary Tree TreeDepth-First SearchBinary TreeDP on Trees | Easy | 88% | 65.8% | ||
| #98 | Validate Binary Search Tree TreeDepth-First SearchBinary Search TreeBinary Tree | Medium | 88% | 36.0% | ||
| #787 | Cheapest Flights Within K Stops Dynamic ProgrammingDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)Shortest Path | Medium | 100% | 42.2% | ||
| #695 | Max Area of Island ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 100% | 74.1% | ||
| #341 | Flatten Nested List Iterator StackTreeDepth-First SearchDesignQueueIterator | Medium | 100% | 65.8% | ||
| #104 | Maximum Depth of Binary Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Easy | 100% | 78.4% | ||
| #133 | Clone Graph Hash TableDepth-First SearchBreadth-First SearchGraph Theory | Medium | 100% | 65.7% | ||
| #329 | Longest Increasing Path in a Matrix ArrayDynamic ProgrammingDepth-First SearchBreadth-First SearchGraph TheoryTopological SortMemoizationMatrixDirected Acyclic Graph | Hard | 93% | 56.8% | ||
| #863 | All Nodes Distance K in Binary Tree Hash TableTreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 89% | 67.8% | ||
| #103 | Binary Tree Zigzag Level Order Traversal TreeBreadth-First SearchBinary Tree | Medium | 100% | 64.1% | ||
| #102 | Binary Tree Level Order Traversal TreeBreadth-First SearchBinary Tree | Medium | 100% | 73.0% | ||
| #934 | Shortest Bridge ArrayDepth-First SearchBreadth-First SearchMatrix | Medium | 100% | 59.6% | ||
| #968 | Binary Tree Cameras Dynamic ProgrammingTreeDepth-First SearchBinary TreeDP on Trees | Hard | 100% | 48.0% | ||
| #64 | Minimum Path Sum ArrayDynamic ProgrammingMatrix | Medium | 100% | 68.5% | ||
| #199 | Binary Tree Right Side View TreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 88% | 70.7% | ||
| #721 | Accounts Merge ArrayHash TableStringDepth-First SearchBreadth-First SearchUnion-FindSorting | Medium | 83% | 61.6% | ||
| #211 | Design Add and Search Words Data Structure StringDepth-First SearchDesignTrie | Medium | 88% | 48.7% | ||
| #987 | Vertical Order Traversal of a Binary Tree Hash TableTreeDepth-First SearchBreadth-First SearchSortingBinary Tree | Hard | 100% | 54.2% | ||
| #130 | Surrounded Regions ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 87% | 0.5% | ||
| #417 | Pacific Atlantic Water Flow ArrayDepth-First SearchBreadth-First SearchMatrix | Medium | 100% | 61.2% | ||
| #235 | Medium | 100% | 70.9% | |||
| #230 | Kth Smallest Element in a BST TreeDepth-First SearchBinary Search TreeBinary Tree | Medium | 88% | 77.0% | ||
| #490 | The Maze ArrayDepth-First SearchBreadth-First SearchMatrix | Medium | 63% | 60.5% | ||
| #2603 | Collect Coins in a Tree ArrayTreeGraph TheoryTopological Sort | Hard | 100% | 39.5% | ||
| #2385 | Amount of Time for Binary Tree to Be Infected Hash TableTreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 100% | 65.7% | ||
| #694 | Number of Distinct Islands ArrayHash TableDepth-First SearchBreadth-First SearchUnion-FindSortingMatrixHash Function | Medium | 92% | 62.9% | ||
| #337 | House Robber III Dynamic ProgrammingTreeDepth-First SearchBinary TreeDP on Trees | Medium | 88% | 56.1% | ||
| #733 | Flood Fill ArrayDepth-First SearchBreadth-First SearchMatrix | Easy | 88% | 68.6% | ||
| #642 | Design Search Autocomplete System StringDepth-First SearchDesignTrieSortingHeap (Priority Queue)Data Stream | Hard | 75% | 50.0% | ||
| #105 | Construct Binary Tree from Preorder and Inorder Traversal ArrayHash TableDivide and ConquerTreeBinary Tree | Medium | 83% | 69.1% | ||
| #886 | Possible Bipartition Depth-First SearchBreadth-First SearchUnion-FindGraph TheoryGraph ColoringBipartite Graph | Medium | 75% | 52.8% | ||
| #101 | Symmetric Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Easy | 66% | 61.6% | ||
| #110 | Balanced Binary Tree TreeDepth-First SearchBinary Tree | Easy | 100% | 58.7% | ||
| #261 | Graph Valid Tree Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 100% | 50.1% | ||
| #1319 | Number of Operations to Make Network Connected Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 100% | 66.9% | ||
| #743 | Network Delay Time Depth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)Shortest PathDijkstra's Algorithm | Medium | 100% | 61.0% | ||
| #314 | Binary Tree Vertical Order Traversal Hash TableTreeDepth-First SearchBreadth-First SearchSortingBinary Tree | Medium | 93% | 57.9% | ||
| #572 | Subtree of Another Tree TreeDepth-First SearchString MatchingBinary TreeHash Function | Easy | 89% | 51.9% | ||
| #1650 | Lowest Common Ancestor of a Binary Tree III Hash TableTwo PointersTreeBinary TreeBinary LiftingLowest Common Ancestor | Medium | 89% | 83.0% | ||
| #785 | Is Graph Bipartite? Depth-First SearchBreadth-First SearchUnion-FindGraph TheoryGraph ColoringBipartite Graph | Medium | 88% | 59.6% | ||
| #96 | Unique Binary Search Trees MathDynamic ProgrammingTreeBinary Search TreeBinary Tree | Medium | 88% | 63.9% | ||
| #1192 | Critical Connections in a Network Depth-First SearchGraph TheoryBiconnected ComponentBridge (Graph) | Hard | 88% | 0.6% | ||
| #226 | Invert Binary Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Easy | 87% | 80.2% | ||
| #100 | Same Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Easy | 85% | 67.5% | ||
| #778 | Swim in Rising Water ArrayBinary SearchDepth-First SearchBreadth-First SearchUnion-FindMinimaxHeap (Priority Queue)MatrixDijkstra's Algorithm | Hard | 78% | 68.0% | ||
| #2858 | Minimum Edge Reversals So Every Node Is Reachable Dynamic ProgrammingDepth-First SearchBreadth-First SearchGraph Theory | Hard | 77% | 60.0% | ||
| #437 | Path Sum III TreeDepth-First SearchBinary Tree | Medium | 76% | 46.5% | ||
| #684 | Redundant Connection Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 75% | 0.7% | ||
| #450 | Delete Node in a BST TreeBinary Search TreeBinary Tree | Medium | 53% | 55.0% | ||
| #841 | Keys and Rooms Depth-First SearchBreadth-First SearchGraph Theory | Medium | 100% | 76.0% | ||
| #109 | Convert Sorted List to Binary Search Tree Linked ListDivide and ConquerTreeBinary Search TreeBinary Tree | Medium | 100% | 66.9% | ||
| #323 | Number of Connected Components in an Undirected Graph Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 100% | 65.1% | ||
| #924 | Minimize Malware Spread ArrayHash TableDepth-First SearchBreadth-First SearchUnion-FindGraph Theory | Hard | 100% | 43.3% | ||
| #1202 | Smallest String With Swaps ArrayHash TableStringDepth-First SearchBreadth-First SearchUnion-FindSorting | Medium | 100% | 60.8% | ||
| #113 | Path Sum II BacktrackingTreeDepth-First SearchBinary Tree | Medium | 63% | 62.5% | ||
| #545 | Boundary of Binary Tree TreeDepth-First SearchBinary Tree | Medium | 63% | 48.2% | ||
| #1743 | Restore the Array From Adjacent Pairs ArrayHash TableDepth-First Search | Medium | 100% | 75.1% | ||
| #1242 | Web Crawler Multithreaded Depth-First SearchBreadth-First SearchConcurrency | Medium | 100% | 51.3% | ||
| #547 | Number of Provinces Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 100% | 70.7% | ||
| #1448 | Count Good Nodes in Binary Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 84% | 73.9% | ||
| #529 | Minesweeper ArrayDepth-First SearchBreadth-First SearchMatrix | Medium | 78% | 68.8% | ||
| #108 | Convert Sorted Array to Binary Search Tree ArrayDivide and ConquerTreeBinary Search TreeBinary Tree | Easy | 75% | 75.8% | ||
| #1631 | Path With Minimum Effort ArrayBinary SearchDepth-First SearchBreadth-First SearchUnion-FindHeap (Priority Queue)MatrixDijkstra's Algorithm | Medium | 67% | 63.6% | ||
| #463 | Island Perimeter ArrayDepth-First SearchBreadth-First SearchMatrix | Easy | 63% | 74.5% | ||
| #652 | Find Duplicate Subtrees Hash TableTreeDepth-First SearchBinary Tree | Medium | 63% | 60.8% | ||
| #112 | Path Sum TreeDepth-First SearchBreadth-First SearchBinary Tree | Easy | 51% | 55.3% | ||
| #419 | Battleships in a Board ArrayDepth-First SearchMatrix | Medium | 100% | 77.6% | ||
| #257 | Binary Tree Paths StringBacktrackingTreeDepth-First SearchBinary Tree | Easy | 89% | 69.0% | ||
| #1233 | Remove Sub-Folders from the Filesystem ArrayStringDepth-First SearchTrie | Medium | 88% | 78.6% | ||
| #270 | Closest Binary Search Tree Value Binary SearchTreeDepth-First SearchBinary Search TreeBinary Tree | Easy | 88% | 49.2% | ||
| #653 | Two Sum IV - Input is a BST Hash TableTwo PointersTreeDepth-First SearchBreadth-First SearchBinary Search TreeBinary Tree | Easy | 88% | 63.5% | ||
| #427 | Construct Quad Tree ArrayDivide and ConquerTreeMatrix | Medium | 88% | 78.5% | ||
| #931 | Minimum Falling Path Sum ArrayDynamic ProgrammingMatrix | Medium | 67% | 60.9% | ||
| #979 | Distribute Coins in Binary Tree TreeDepth-First SearchBinary TreeDP on Trees | Medium | 64% | 77.3% | ||
| #173 | Binary Search Tree Iterator StackTreeDesignBinary Search TreeBinary TreeIterator | Medium | 63% | 76.7% | ||
| #617 | Merge Two Binary Trees TreeDepth-First SearchBreadth-First SearchBinary Tree | Easy | 63% | 79.1% | ||
| #662 | Maximum Width of Binary Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 63% | 45.8% | ||
| #116 | Populating Next Right Pointers in Each Node Linked ListTreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 53% | 67.4% | ||
| #515 | Find Largest Value in Each Tree Row TreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 52% | 66.3% | ||
| #365 | Water and Jug Problem MathDepth-First SearchBreadth-First SearchBézout's LemmaEuclidean AlgorithmGreatest Common DivisorExtended Euclidean Algorithm | Medium | 51% | 45.9% | ||
| #2196 | Create Binary Tree From Descriptions ArrayHash TableTreeBinary Tree | Medium | 100% | 83.9% | ||
| #310 | Minimum Height Trees Depth-First SearchBreadth-First SearchGraph TheoryTopological Sort | Medium | 100% | 42.6% | ||
| #111 | Minimum Depth of Binary Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Easy | 100% | 53.3% | ||
| #1236 | Web Crawler StringDepth-First SearchBreadth-First SearchInteractive | Medium | 100% | 68.8% | ||
| #2360 | Longest Cycle in a Graph Depth-First SearchBreadth-First SearchGraph TheoryTopological SortKosaraju's AlgorithmTarjan's SCC Algorithm | Hard | 88% | 50.9% | ||
| #513 | Find Bottom Left Tree Value TreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 88% | 72.4% | ||
| #2101 | Detonate the Maximum Bombs ArrayMathDepth-First SearchBreadth-First SearchGraph TheoryGeometry | Medium | 88% | 50.3% | ||
| #1948 | Delete Duplicate Folders in System ArrayHash TableStringDepth-First SearchTrieSortingHash Function | Hard | 88% | 77.4% | ||
| #834 | Sum of Distances in Tree Dynamic ProgrammingTreeDepth-First SearchGraph TheoryDP on Trees | Hard | 85% | 65.7% | ||
| #430 | Flatten a Multilevel Doubly Linked List Linked ListDepth-First SearchDoubly-Linked List | Medium | 79% | 63.1% | ||
| #129 | Sum Root to Leaf Numbers TreeDepth-First SearchBinary Tree | Medium | 78% | 70.1% | ||
| #3607 | Power Grid Maintenance ArrayHash TableDepth-First SearchBreadth-First SearchUnion-FindGraph TheoryHeap (Priority Queue)Ordered Set | Medium | 75% | 56.1% | ||
| #222 | Count Complete Tree Nodes Binary SearchBit ManipulationTreeBinary Tree | Medium | 68% | 73.1% | ||
| #851 | Loud and Rich ArrayDepth-First SearchGraph TheoryTopological SortDirected Acyclic Graph | Medium | 65% | 63.8% | ||
| #765 | Couples Holding Hands GreedyDepth-First SearchBreadth-First SearchUnion-FindGraph Theory | Hard | 63% | 0.6% | ||
| #701 | Insert into a Binary Search Tree TreeBinary Search TreeBinary Tree | Medium | 63% | 73.5% | ||
| #106 | Construct Binary Tree from Inorder and Postorder Traversal ArrayHash TableDivide and ConquerTreeBinary Tree | Medium | 63% | 69.1% | ||
| #94 | Binary Tree Inorder Traversal StackTreeDepth-First SearchBinary Tree | Easy | 50% | 80.3% | ||
| #802 | Find Eventual Safe States Depth-First SearchBreadth-First SearchGraph TheoryTopological SortKosaraju's AlgorithmTarjan's SCC Algorithm | Medium | 50% | 71.2% | ||
| #117 | Populating Next Right Pointers in Each Node II Linked ListTreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 50% | 57.8% | ||
| #428 | Serialize and Deserialize N-ary Tree StringTreeDepth-First SearchBreadth-First Search | Hard | 39% | 68.9% | ||
| #1245 | Tree Diameter TreeDepth-First SearchBreadth-First SearchGraph TheoryTopological SortDP on Trees | Medium | 39% | 61.3% | ||
| #1559 | Detect Cycles in 2D Grid ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 100% | 63.4% | ||
| #285 | Inorder Successor in BST TreeDepth-First SearchBinary Search TreeBinary Tree | Medium | 100% | 51.2% | ||
| #2246 | Longest Path With Different Adjacent Characters ArrayStringTreeDepth-First SearchGraph TheoryTopological Sort | Hard | 100% | 0.5% | ||
| #2791 | Count Paths That Can Form a Palindrome in a Tree Hash TableBit ManipulationTreeDepth-First Search | Hard | 100% | 0.5% | ||
| #339 | Nested List Weight Sum Depth-First SearchBreadth-First Search | Medium | 88% | 86.0% | ||
| #2096 | Step-By-Step Directions From a Binary Tree Node to Another StringTreeDepth-First SearchBinary TreeBinary LiftingLowest Common Ancestor | Medium | 88% | 56.5% | ||
| #1022 | Sum of Root To Leaf Binary Numbers TreeDepth-First SearchBinary Tree | Easy | 88% | 76.6% | ||
| #2467 | Most Profitable Path in a Tree ArrayTreeDepth-First SearchBreadth-First SearchGraph Theory | Medium | 88% | 67.3% | ||
| #938 | Range Sum of BST TreeDepth-First SearchBinary Search TreeBinary Tree | Easy | 78% | 87.6% | ||
| #366 | Find Leaves of Binary Tree TreeDepth-First SearchBinary TreeDP on Trees | Medium | 77% | 81.3% | ||
| #690 | Employee Importance ArrayHash TableTreeDepth-First SearchBreadth-First Search | Medium | 75% | 69.6% | ||
| #404 | Sum of Left Leaves TreeDepth-First SearchBreadth-First SearchBinary Tree | Easy | 75% | 62.9% | ||
| #1028 | Recover a Tree From Preorder Traversal StringTreeDepth-First SearchBinary Tree | Hard | 70% | 83.3% | ||
| #2493 | Divide Nodes Into the Maximum Number of Groups Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Hard | 63% | 66.9% | ||
| #386 | Lexicographical Numbers Depth-First SearchTrie | Medium | 53% | 76.3% | ||
| #993 | Cousins in Binary Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Easy | 52% | 59.5% | ||
| #872 | Leaf-Similar Trees TreeDepth-First SearchBinary Tree | Easy | 50% | 70.3% | ||
| #1462 | Course Schedule IV Depth-First SearchBreadth-First SearchGraph TheoryTopological Sort | Medium | 50% | 60.0% | ||
| #1008 | Construct Binary Search Tree from Preorder Traversal ArrayStackTreeBinary Search TreeMonotonic StackBinary Tree | Medium | 38% | 84.4% | ||
| #1020 | Number of Enclaves ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 27% | 72.0% | ||
| #700 | Search in a Binary Search Tree TreeBinary Search TreeBinary Tree | Easy | 25% | 82.9% | ||
| #107 | Binary Tree Level Order Traversal II TreeBreadth-First SearchBinary Tree | Medium | 25% | 68.6% | ||
| #889 | Construct Binary Tree from Preorder and Postorder Traversal ArrayHash TableDivide and ConquerTreeBinary Tree | Medium | 25% | 78.1% | ||
| #1267 | Count Servers that Communicate ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrixCounting | Medium | 25% | 73.5% | ||
| #1367 | Linked List in Binary Tree Linked ListTreeDepth-First SearchBinary Tree | Medium | 100% | 52.0% | ||
| #814 | Binary Tree Pruning TreeDepth-First SearchBinary Tree | Medium | 100% | 72.5% | ||
| #655 | Print Binary Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 100% | 66.7% | ||
| #255 | Verify Preorder Sequence in Binary Search Tree ArrayStackTreeBinary Search TreeRecursionMonotonic StackBinary Tree | Medium | 100% | 51.8% | ||
| #958 | Check Completeness of a Binary Tree TreeBreadth-First SearchBinary Tree | Medium | 75% | 59.3% | ||
| #1026 | Maximum Difference Between Node and Ancestor TreeDepth-First SearchBinary Tree | Medium | 63% | 78.2% | ||
| #1443 | Minimum Time to Collect All Apples in a Tree Hash TableTreeDepth-First SearchBreadth-First SearchDP on Trees | Medium | 63% | 63.8% | ||
| #797 | All Paths From Source to Target BacktrackingDepth-First SearchBreadth-First SearchGraph TheoryDirected Acyclic Graph | Medium | 63% | 83.7% | ||
| #2316 | Count Unreachable Pairs of Nodes in an Undirected Graph Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 63% | 0.5% | ||
| #2127 | Maximum Employees to Be Invited to a Meeting ArrayDynamic ProgrammingDepth-First SearchGraph TheoryTopological SortKosaraju's AlgorithmTarjan's SCC Algorithm | Hard | 60% | 61.8% | ||
| #1203 | Sort Items by Groups Respecting Dependencies Depth-First SearchBreadth-First SearchGraph TheoryTopological SortDirected Acyclic Graph | Hard | 56% | 66.0% | ||
| #505 | The Maze II ArrayDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest PathDijkstra's AlgorithmHeuristic SearchA* Search | Medium | 54% | 55.2% | ||
| #1466 | Reorder Routes to Make All Paths Lead to the City Zero Depth-First SearchBreadth-First SearchGraph Theory | Medium | 50% | 66.0% | ||
| #2583 | Kth Largest Sum in a Binary Tree TreeBreadth-First SearchSortingBinary Tree | Medium | 39% | 59.0% | ||
| #839 | Similar String Groups ArrayHash TableStringDepth-First SearchBreadth-First SearchUnion-Find | Hard | 38% | 56.4% | ||
| #1382 | Balance a Binary Search Tree Divide and ConquerGreedyTreeDepth-First SearchBinary Search TreeBinary Tree | Medium | 38% | 86.3% | ||
| #1971 | Find if Path Exists in Graph Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Easy | 38% | 55.5% | ||
| #1254 | Number of Closed Islands ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 38% | 67.2% | ||
| #1373 | Maximum Sum BST in Binary Tree Dynamic ProgrammingTreeDepth-First SearchBinary Search TreeBinary TreeDP on Trees | Hard | 38% | 48.1% | ||
| #1339 | Maximum Product of Splitted Binary Tree TreeDepth-First SearchBinary Tree | Medium | 38% | 55.8% | ||
| #2477 | Minimum Fuel Cost to Report to the Capital TreeDepth-First SearchBreadth-First SearchGraph Theory | Medium | 38% | 65.4% | ||
| #894 | All Possible Full Binary Trees Dynamic ProgrammingTreeRecursionMemoizationBinary Tree | Medium | 38% | 82.8% | ||
| #95 | Unique Binary Search Trees II Dynamic ProgrammingBacktrackingTreeBinary Search TreeBinary Tree | Medium | 28% | 62.8% | ||
| #144 | Binary Tree Preorder Traversal StackTreeDepth-First SearchBinary Tree | Easy | 27% | 76.2% | ||
| #145 | Binary Tree Postorder Traversal StackTreeDepth-First SearchBinary Tree | Easy | 25% | 78.5% | ||
| #2236 | Root Equals Sum of Children TreeBinary Tree | Easy | 25% | 85.1% | ||
| #965 | Univalued Binary Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Easy | 100% | 73.2% | ||
| #3068 | Find the Maximum Sum of Node Values ArrayDynamic ProgrammingGreedyBit ManipulationTreeSorting | Hard | 100% | 69.4% | ||
| #3203 | Find Minimum Diameter After Merging Two Trees TreeDepth-First SearchBreadth-First SearchGraph Theory | Hard | 100% | 57.0% | ||
| #1306 | Jump Game III ArrayDepth-First SearchBreadth-First Search | Medium | 100% | 70.3% | ||
| #1036 | Escape a Large Maze ArrayHash TableDepth-First SearchBreadth-First SearchBidirectional Search | Hard | 100% | 36.8% | ||
| #783 | Minimum Distance Between BST Nodes TreeDepth-First SearchBreadth-First SearchBinary Search TreeBinary Tree | Easy | 88% | 61.6% | ||
| #1034 | Coloring A Border ArrayDepth-First SearchBreadth-First SearchMatrix | Medium | 88% | 0.5% | ||
| #250 | Count Univalue Subtrees TreeDepth-First SearchBinary TreeDP on Trees | Medium | 88% | 57.5% | ||
| #2359 | Find Closest Node to Given Two Nodes Depth-First SearchGraph Theory | Medium | 88% | 53.1% | ||
| #1722 | Minimize Hamming Distance After Swap Operations ArrayDepth-First SearchUnion-Find | Medium | 79% | 0.7% | ||
| #385 | Mini Parser StringStackDepth-First Search | Medium | 75% | 42.9% | ||
| #449 | Serialize and Deserialize BST StringTreeDepth-First SearchBreadth-First SearchDesignBinary Search TreeBinary Tree | Medium | 68% | 59.8% | ||
| #1325 | Delete Leaves With a Given Value TreeDepth-First SearchBinary Tree | Medium | 67% | 77.2% | ||
| #426 | Convert Binary Search Tree to Sorted Doubly Linked List Linked ListStackTreeDepth-First SearchBinary Search TreeBinary TreeDoubly-Linked List | Medium | 64% | 65.6% | ||
| #1315 | Sum of Nodes with Even-Valued Grandparent TreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 63% | 86.0% | ||
| #1110 | Delete Nodes And Return Forest ArrayHash TableTreeDepth-First SearchBinary Tree | Medium | 63% | 72.5% | ||
| #2192 | All Ancestors of a Node in a Directed Acyclic Graph Depth-First SearchBreadth-First SearchGraph TheoryTopological SortDirected Acyclic Graph | Medium | 63% | 62.3% | ||
| #1676 | Lowest Common Ancestor of a Binary Tree IV Hash TableTreeDepth-First SearchBinary TreeBinary LiftingLowest Common Ancestor | Medium | 63% | 79.6% | ||
| #2265 | Count Nodes Equal to Average of Subtree TreeDepth-First SearchBinary Tree | Medium | 53% | 86.8% | ||
| #1644 | Lowest Common Ancestor of a Binary Tree II TreeDepth-First SearchBinary TreeBinary LiftingLowest Common Ancestor | Medium | 51% | 69.7% | ||
| #737 | Sentence Similarity II ArrayHash TableStringDepth-First SearchBreadth-First SearchUnion-Find | Medium | 50% | 51.4% | ||
| #298 | Binary Tree Longest Consecutive Sequence TreeDepth-First SearchBinary TreeDP on Trees | Medium | 50% | 54.8% | ||
| #669 | Trim a Binary Search Tree TreeDepth-First SearchBinary Search TreeBinary Tree | Medium | 42% | 66.8% | ||
| #1970 | Last Day Where You Can Still Cross ArrayBinary SearchDepth-First SearchBreadth-First SearchUnion-FindMatrix | Hard | 41% | 68.7% | ||
| #582 | Kill Process ArrayHash TableTreeDepth-First SearchBreadth-First Search | Medium | 39% | 70.7% | ||
| #865 | Smallest Subtree with all the Deepest Nodes Hash TableTreeDepth-First SearchBreadth-First SearchBinary TreeBinary LiftingLowest Common AncestorDP on Trees | Medium | 39% | 77.6% | ||
| #1123 | Lowest Common Ancestor of Deepest Leaves Hash TableTreeDepth-First SearchBreadth-First SearchBinary TreeBinary LiftingLowest Common AncestorDP on Trees | Medium | 38% | 79.5% | ||
| #2872 | Maximum Number of K-Divisible Components TreeDepth-First Search | Hard | 38% | 74.0% | ||
| #1161 | Maximum Level Sum of a Binary Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 28% | 70.0% | ||
| #654 | Maximum Binary Tree ArrayDivide and ConquerStackTreeMonotonic StackBinary TreeCartesian Tree | Medium | 27% | 86.4% | ||
| #1483 | Kth Ancestor of a Tree Node Binary SearchDynamic ProgrammingBit ManipulationTreeDepth-First SearchBreadth-First SearchDesignBinary Lifting | Hard | 27% | 38.9% | ||
| #388 | Longest Absolute File Path StringStackDepth-First Search | Medium | 26% | 49.6% | ||
| #501 | Find Mode in Binary Search Tree TreeDepth-First SearchBinary Search TreeBinary Tree | Easy | 25% | 59.1% | ||
| #637 | Average of Levels in Binary Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Easy | 25% | 75.0% | ||
| #538 | Convert BST to Greater Tree TreeDepth-First SearchBinary Search TreeBinary Tree | Medium | 25% | 71.8% | ||
| #2322 | Minimum Score After Removals on a Tree ArrayBit ManipulationTreeDepth-First Search | Hard | 25% | 76.1% | ||
| #1289 | Minimum Falling Path Sum II ArrayDynamic ProgrammingMatrix | Hard | 25% | 63.0% | ||
| #2685 | Count the Number of Complete Components Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 16% | 80.8% | ||
| #2658 | Maximum Number of Fish in a Grid ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 13% | 70.3% | ||
| #364 | Nested List Weight Sum II StackDepth-First SearchBreadth-First Search | Medium | 100% | 67.0% | ||
| #3367 | Maximize Sum of Weights after Edge Removals Dynamic ProgrammingTreeDepth-First SearchSorting | Hard | 100% | 0.3% | ||
| #1391 | Check if There is a Valid Path in a Grid ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 100% | 64.5% | ||
| #563 | Binary Tree Tilt TreeDepth-First SearchBinary TreeDP on Trees | Easy | 100% | 66.1% | ||
| #3067 | Count Pairs of Connectable Servers in a Weighted Tree Network ArrayTreeDepth-First Search | Medium | 100% | 56.2% | ||
| #1993 | Operations on Tree ArrayHash TableTreeDepth-First SearchBreadth-First SearchDesign | Medium | 100% | 45.7% | ||
| #2471 | Minimum Number of Operations to Sort a Binary Tree by Level TreeBreadth-First SearchBinary Tree | Medium | 100% | 74.3% | ||
| #749 | Contain Virus ArrayDepth-First SearchBreadth-First SearchMatrixSimulation | Hard | 100% | 55.1% | ||
| #623 | Add One Row to Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 100% | 64.2% | ||
| #3715 | Sum of Perfect Square Ancestors ArrayHash TableMathTreeDepth-First SearchCountingNumber Theory | Hard | 92% | 42.8% | ||
| #510 | Inorder Successor in BST II TreeBinary Search TreeBinary Tree | Medium | 78% | 61.1% | ||
| #1302 | Deepest Leaves Sum TreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 75% | 86.6% | ||
| #2049 | Count Nodes With the Highest Score ArrayTreeDepth-First SearchBinary TreeDP on Trees | Medium | 75% | 52.9% | ||
| #1102 | Path With Maximum Minimum Value ArrayBinary SearchDepth-First SearchBreadth-First SearchUnion-FindHeap (Priority Queue)MatrixDijkstra's Algorithm | Medium | 68% | 54.7% | ||
| #272 | Closest Binary Search Tree Value II Two PointersStackTreeDepth-First SearchBinary Search TreeHeap (Priority Queue)Binary Tree | Hard | 63% | 61.2% | ||
| #671 | Second Minimum Node In a Binary Tree TreeDepth-First SearchBinary Tree | Easy | 63% | 46.2% | ||
| #742 | Closest Leaf in a Binary Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 63% | 47.5% | ||
| #3387 | Maximize Amount After Two Days of Conversions ArrayStringDepth-First SearchBreadth-First SearchGraph Theory | Medium | 60% | 61.7% | ||
| #1038 | Binary Search Tree to Greater Sum Tree TreeDepth-First SearchBinary Search TreeBinary Tree | Medium | 56% | 88.4% | ||
| #514 | Freedom Trail StringDynamic ProgrammingDepth-First SearchBreadth-First Search | Hard | 54% | 59.4% | ||
| #472 | Concatenated Words ArrayStringDynamic ProgrammingDepth-First SearchTrieSorting | Hard | 53% | 49.9% | ||
| #565 | Array Nesting ArrayDepth-First Search | Medium | 51% | 56.7% | ||
| #536 | Construct Binary Tree from String StringStackTreeDepth-First SearchBinary Tree | Medium | 50% | 58.7% | ||
| #1530 | Number of Good Leaf Nodes Pairs TreeDepth-First SearchBinary TreeDP on Trees | Medium | 50% | 71.8% | ||
| #2097 | Valid Arrangement of Pairs ArrayDepth-First SearchGraph TheoryEulerian CircuitEulerian PathSemi-Eulerian Graph | Hard | 50% | 66.6% | ||
| #1778 | Shortest Path in a Hidden Grid ArrayDepth-First SearchBreadth-First SearchMatrixInteractive | Medium | 40% | 44.7% | ||
| #1522 | Diameter of N-Ary Tree TreeDepth-First SearchDP on Trees | Medium | 38% | 75.5% | ||
| #1609 | Even Odd Tree TreeBreadth-First SearchBinary Tree | Medium | 38% | 67.2% | ||
| #2458 | Height of Binary Tree After Subtree Removal Queries ArrayTreeDepth-First SearchBreadth-First SearchBinary Tree | Hard | 38% | 54.9% | ||
| #530 | Minimum Absolute Difference in BST TreeDepth-First SearchBreadth-First SearchBinary Search TreeBinary Tree | Easy | 29% | 59.5% | ||
| #508 | Most Frequent Subtree Sum Hash TableTreeDepth-First SearchBinary TreeDP on Trees | Medium | 27% | 69.4% | ||
| #1361 | Validate Binary Tree Nodes TreeDepth-First SearchBreadth-First SearchUnion-FindGraph TheoryBinary Tree | Medium | 25% | 44.2% | ||
| #2596 | Check Knight Tour Configuration ArrayDepth-First SearchBreadth-First SearchMatrixSimulation | Medium | 25% | 61.7% | ||
| #606 | Construct String from Binary Tree StringTreeDepth-First SearchBinary Tree | Medium | 25% | 70.8% | ||
| #1506 | Find Root of N-Ary Tree Hash TableBit ManipulationTreeDepth-First Search | Medium | 25% | 78.6% | ||
| #549 | Binary Tree Longest Consecutive Sequence II TreeDepth-First SearchBinary TreeDP on Trees | Medium | 25% | 50.1% | ||
| #919 | Complete Binary Tree Inserter TreeBreadth-First SearchDesignBinary Tree | Medium | 25% | 65.2% | ||
| #2421 | Number of Good Paths ArrayHash TableTreeUnion-FindGraph TheorySorting | Hard | 25% | 56.5% | ||
| #590 | N-ary Tree Postorder Traversal StackTreeDepth-First Search | Easy | 13% | 81.1% | ||
| #3559 | Number of Ways to Assign Edge Weights II ArrayMathDynamic ProgrammingBit ManipulationTreeDepth-First Search | Hard | 13% | 72.5% | ||
| #3310 | Remove Methods From Project Depth-First SearchBreadth-First SearchGraph Theory | Medium | 13% | 0.7% | ||
| #429 | N-ary Tree Level Order Traversal TreeBreadth-First Search | Medium | 13% | 71.6% | ||
| #1932 | Merge BSTs to Create Single BST ArrayHash TableTreeDepth-First SearchBinary Search TreeBinary Tree | Hard | 13% | 39.6% | ||
| #1992 | Find All Groups of Farmland ArrayDepth-First SearchBreadth-First SearchMatrix | Medium | 100% | 75.5% | ||
| #3372 | Maximize the Number of Target Nodes After Connecting Trees I TreeDepth-First SearchBreadth-First Search | Medium | 100% | 69.4% | ||
| #3373 | Maximize the Number of Target Nodes After Connecting Trees II TreeDepth-First SearchBreadth-First Search | Hard | 100% | 73.1% | ||
| #2368 | Reachable Nodes With Restrictions ArrayHash TableTreeDepth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 100% | 60.6% | ||
| #776 | Split BST TreeBinary Search TreeRecursionBinary Tree | Medium | 100% | 82.2% | ||
| #3123 | Find Edges in Shortest Paths Depth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)Shortest Path | Hard | 100% | 46.9% | ||
| #928 | Minimize Malware Spread II ArrayHash TableDepth-First SearchBreadth-First SearchUnion-FindGraph Theory | Hard | 100% | 45.8% | ||
| #1457 | Pseudo-Palindromic Paths in a Binary Tree Bit ManipulationTreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 100% | 68.4% | ||
| #3710 | Maximum Partition Factor ArrayBinary SearchDepth-First SearchBreadth-First SearchUnion-FindGraph Theory | Hard | 93% | 32.1% | ||
| #1519 | Number of Nodes in the Sub-Tree With the Same Label Hash TableTreeDepth-First SearchBreadth-First SearchCountingDP on Trees | Medium | 88% | 55.5% | ||
| #559 | Maximum Depth of N-ary Tree TreeDepth-First SearchBreadth-First Search | Easy | 88% | 73.7% | ||
| #1104 | Path In Zigzag Labelled Binary Tree MathTreeBinary Tree | Medium | 88% | 75.8% | ||
| #2328 | Number of Increasing Paths in a Grid ArrayDynamic ProgrammingDepth-First SearchBreadth-First SearchGraph TheoryTopological SortMemoizationMatrix | Hard | 88% | 57.3% | ||
| #1600 | Throne Inheritance Hash TableTreeDepth-First SearchDesign | Medium | 88% | 67.4% | ||
| #1377 | Frog Position After T Seconds TreeDepth-First SearchBreadth-First SearchGraph Theory | Hard | 83% | 38.7% | ||
| #3619 | Count Islands With Total Value Divisible by K ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 79% | 56.2% | ||
| #156 | Binary Tree Upside Down TreeDepth-First SearchBinary Tree | Medium | 75% | 65.5% | ||
| #3004 | Maximum Subtree of the Same Color ArrayDynamic ProgrammingTreeDepth-First Search | Medium | 75% | 58.8% | ||
| #1724 | Checking Existence of Edge Length Limited Paths II Depth-First SearchUnion-FindGraph TheoryDesignSortingHeap (Priority Queue)Minimum Spanning Tree | Hard | 75% | 51.6% | ||
| #1042 | Flower Planting With No Adjacent Depth-First SearchBreadth-First SearchGraph TheoryGraph Coloring | Medium | 70% | 53.9% | ||
| #2307 | Check for Contradictions in Equations ArrayStringDepth-First SearchUnion-FindGraph Theory | Hard | 50% | 44.0% | ||
| #676 | Implement Magic Dictionary Hash TableStringDepth-First SearchDesignTrie | Medium | 45% | 58.0% | ||
| #2204 | Distance to a Cycle in Undirected Graph Depth-First SearchBreadth-First SearchGraph TheoryTopological Sort | Hard | 38% | 73.9% | ||
| #1820 | Maximum Number of Accepted Invitations ArrayDepth-First SearchGraph TheoryMatrixMaximum FlowMaximum MatchingBipartite GraphEdmonds–Karp AlgorithmMPM AlgorithmPush-Relabel AlgorithmMatching (Graph)Flow NetworkDinic's Algorithm | Medium | 38% | 52.7% | ||
| #333 | Largest BST Subtree Dynamic ProgrammingTreeDepth-First SearchBinary Search TreeBinary TreeDP on Trees | Medium | 27% | 45.9% | ||
| #1810 | Minimum Path Cost in a Hidden Grid ArrayDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixInteractiveShortest Path | Medium | 27% | 59.0% | ||
| #1485 | Clone Binary Tree With Random Pointer Hash TableTreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 27% | 81.3% | ||
| #2641 | Cousins in Binary Tree II Hash TableTreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 27% | 75.9% | ||
| #711 | Number of Distinct Islands II ArrayHash TableDepth-First SearchBreadth-First SearchUnion-FindSortingMatrixHash Function | Hard | 25% | 55.5% | ||
| #1740 | Find Distance in a Binary Tree Hash TableTreeDepth-First SearchBreadth-First SearchBinary TreeBinary LiftingLowest Common Ancestor | Medium | 25% | 74.4% | ||
| #1305 | All Elements in Two Binary Search Trees TreeDepth-First SearchBinary Search TreeSortingBinary Tree | Medium | 25% | 80.3% | ||
| #988 | Smallest String Starting From Leaf StringBacktrackingTreeDepth-First SearchBinary Tree | Medium | 25% | 61.3% | ||
| #1145 | Binary Tree Coloring Game TreeDepth-First SearchBinary Tree | Medium | 25% | 53.0% | ||
| #1261 | Find Elements in a Contaminated Binary Tree Hash TableTreeDepth-First SearchBreadth-First SearchDesignBinary Tree | Medium | 25% | 84.1% | ||
| #3419 | Minimize the Maximum Edge Weight of Graph Binary SearchDepth-First SearchBreadth-First SearchGraph TheoryShortest Path | Medium | 25% | 45.1% | ||
| #3593 | Minimum Increments to Equalize Leaf Paths ArrayDynamic ProgrammingTreeDepth-First Search | Medium | 16% | 41.4% | ||
| #3558 | Number of Ways to Assign Edge Weights I MathTreeDepth-First Search | Medium | 13% | 64.0% | ||
| #3562 | Maximum Profit from Trading Stocks with Discounts ArrayDynamic ProgrammingTreeDepth-First Search | Hard | 13% | 56.5% | ||
| #897 | Increasing Order Search Tree StackTreeDepth-First SearchBinary Search TreeBinary Tree | Easy | 13% | 79.0% | ||
| #589 | N-ary Tree Preorder Traversal StackTreeDepth-First Search | Easy | 13% | 76.9% | ||
| #1372 | Longest ZigZag Path in a Binary Tree Dynamic ProgrammingTreeDepth-First SearchBinary TreeDP on Trees | Medium | 13% | 67.3% | ||
| #3235 | Check if the Rectangle Corner Is Reachable ArrayMathDepth-First SearchBreadth-First SearchUnion-FindGeometry | Hard | 13% | 25.2% | ||
| #2876 | Count Visited Nodes in a Directed Graph Dynamic ProgrammingDepth-First SearchGraph TheoryTopological SortMemoizationKosaraju's AlgorithmTarjan's SCC Algorithm | Hard | 100% | 31.1% | ||
| #2509 | Cycle Length Queries in a Tree ArrayTreeBinary TreeBinary LiftingLowest Common Ancestor | Hard | 100% | 60.6% | ||
| #2440 | Create Components With Same Value ArrayMathTreeDepth-First SearchEnumeration | Hard | 100% | 53.7% | ||
| #666 | Path Sum IV ArrayHash TableTreeDepth-First SearchBinary Tree | Medium | 100% | 62.9% | ||
| #2005 | Subtree Removal Game with Fibonacci Tree MathDynamic ProgrammingTreeBinary TreeGame TheorySprague–Grundy Theorem | Hard | 100% | 57.8% | ||
| #2846 | Minimum Edge Weight Equilibrium Queries in a Tree ArrayDynamic ProgrammingBit ManipulationTreeDepth-First Search | Hard | 90% | 47.0% | ||
| #2378 | Choose Edges to Maximize Score in a Tree Dynamic ProgrammingTreeDepth-First Search | Medium | 90% | 56.8% | ||
| #1257 | Smallest Common Region ArrayHash TableStringTreeDepth-First SearchBreadth-First SearchBinary LiftingLowest Common Ancestor | Medium | 88% | 68.3% | ||
| #1916 | Count Ways to Build Rooms in an Ant Colony ArrayMathDynamic ProgrammingTreeDepth-First SearchGraph TheoryTopological SortCombinatoricsDP on TreesFermat's Little Theorem | Hard | 88% | 51.8% | ||
| #3787 | Find Diameter Endpoints of a Tree TreeBreadth-First SearchGraph Theory | Medium | 84% | 66.9% | ||
| #3820 | Pythagorean Distance Nodes in a Tree TreeBreadth-First Search | Medium | 78% | 58.0% | ||
| #2920 | Maximum Points After Collecting Coins From All Nodes ArrayDynamic ProgrammingBit ManipulationTreeDepth-First SearchMemoizationDP on Trees | Hard | 75% | 36.9% | ||
| #3383 | Minimum Runes to Add to Cast Spell ArrayDepth-First SearchBreadth-First SearchGraph TheoryTopological Sort | Hard | 75% | 44.7% | ||
| #3575 | Maximum Good Subtree Score ArrayDynamic ProgrammingBit ManipulationTreeDepth-First SearchBitmask | Hard | 75% | 45.7% | ||
| #2445 | Number of Nodes With Value One ArrayTreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 75% | 66.3% | ||
| #2867 | Count Valid Paths in a Tree MathDynamic ProgrammingTreeDepth-First SearchNumber TheoryPrimality TestSieve TheoryPrime Number Sieve | Hard | 64% | 36.6% | ||
| #3939 | Count Non Adjacent Subsets in a Rooted Tree ArrayDynamic ProgrammingTreeDepth-First Search | Hard | 63% | 56.1% | ||
| #3515 | Shortest Path in a Weighted Tree ArrayTreeDepth-First SearchBinary Indexed TreeSegment Tree | Hard | 56% | 42.6% | ||
| #3313 | Find the Last Marked Nodes in Tree TreeDepth-First Search | Hard | 55% | 56.5% | ||
| #3528 | Unit Conversion I Depth-First SearchBreadth-First SearchGraph Theory | Medium | 52% | 54.1% | ||
| #1719 | Number Of Ways To Reconstruct A Tree ArrayHash TableTreeGraph TheorySimulation | Hard | 50% | 46.2% | ||
| #3481 | Apply Substitutions ArrayHash TableStringDepth-First SearchBreadth-First SearchGraph TheoryTopological Sort | Medium | 43% | 77.9% | ||
| #2673 | Make Costs of Paths Equal in a Binary Tree ArrayDynamic ProgrammingGreedyTreeBinary Tree | Medium | 39% | 58.8% | ||
| #672 | Bulb Switcher II MathBit ManipulationDepth-First SearchBreadth-First Search | Medium | 38% | 50.4% | ||
| #3772 | Maximum Subgraph Score in a Tree ArrayDynamic ProgrammingTreeDepth-First Search | Hard | 29% | 71.0% | ||
| #1628 | Design an Expression Tree With Evaluate Function ArrayMathStackTreeDesignBinary Tree | Medium | 28% | 82.5% | ||
| #1273 | Delete Tree Nodes ArrayTreeDepth-First SearchBreadth-First SearchDP on Trees | Medium | 27% | 61.6% | ||
| #1469 | Find All The Lonely Nodes TreeDepth-First SearchBreadth-First SearchBinary Tree | Easy | 27% | 84.1% | ||
| #3157 | Find the Level of Tree with Minimum Sum TreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 27% | 69.5% | ||
| #1379 | Find a Corresponding Node of a Binary Tree in a Clone of That Tree TreeDepth-First SearchBreadth-First SearchBinary Tree | Easy | 27% | 85.9% | ||
| #1586 | Binary Search Tree Iterator II StackTreeDesignBinary Search TreeBinary TreeIterator | Medium | 25% | 63.5% | ||
| #998 | Maximum Binary Tree II TreeBinary Tree | Medium | 25% | 70.7% | ||
| #1973 | Count Nodes Equal to Sum of Descendants TreeDepth-First SearchBinary Tree | Medium | 25% | 77.3% | ||
| #3535 | Unit Conversion II ArrayMathDepth-First SearchBreadth-First SearchGraph Theory | Medium | 25% | 65.8% | ||
| #1214 | Two Sum BSTs Two PointersBinary SearchStackTreeDepth-First SearchBinary Search TreeBinary Tree | Medium | 25% | 68.2% | ||
| #1080 | Insufficient Nodes in Root to Leaf Paths TreeDepth-First SearchBinary Tree | Medium | 25% | 55.4% | ||
| #2973 | Find Number of Coins to Place in Tree Nodes Dynamic ProgrammingTreeDepth-First SearchSortingHeap (Priority Queue)DP on Trees | Hard | 25% | 37.7% | ||
| #3786 | Total Sum of Interaction Cost in Tree Groups ArrayTreeDepth-First Search | Hard | 25% | 54.4% | ||
| #663 | Equal Tree Partition TreeDepth-First SearchBinary Tree | Medium | 25% | 42.3% | ||
| #1120 | Maximum Average Subtree TreeDepth-First SearchBinary Tree | Medium | 25% | 67.0% | ||
| #1490 | Clone N-ary Tree Hash TableTreeDepth-First SearchBreadth-First Search | Medium | 25% | 83.2% | ||
| #1597 | Build Binary Expression Tree From Infix Expression StringStackTreeBinary Tree | Hard | 25% | 62.9% | ||
| #2123 | Minimum Operations to Remove Adjacent Ones in Matrix ArrayDepth-First SearchGraph TheoryMatrixEdmonds–Karp AlgorithmMPM AlgorithmPush-Relabel AlgorithmFlow NetworkDinic's Algorithm | Hard | 25% | 43.6% | ||
| #753 | Cracking the Safe StringDepth-First SearchGraph TheoryEulerian CircuitEulerian PathEulerian Graph | Hard | 25% | 58.5% | ||
| #3327 | Check if DFS Strings Are Palindromes ArrayHash TableStringTreeDepth-First SearchHash Function | Hard | 25% | 20.8% | ||
| #331 | Verify Preorder Serialization of a Binary Tree StringStackTreeBinary Tree | Medium | 25% | 47.5% | ||
| #2476 | Closest Nodes Queries in a Binary Search Tree ArrayBinary SearchTreeDepth-First SearchBinary Search TreeBinary Tree | Medium | 25% | 44.7% | ||
| #2556 | Disconnect Path in a Binary Matrix by at Most One Flip ArrayDynamic ProgrammingDepth-First SearchBreadth-First SearchMatrix | Medium | 25% | 28.0% | ||
| #302 | Smallest Rectangle Enclosing Black Pixels ArrayBinary SearchDepth-First SearchBreadth-First SearchMatrix | Hard | 25% | 61.0% | ||
| #2331 | Evaluate Boolean Binary Tree TreeDepth-First SearchBinary Tree | Easy | 25% | 82.4% | ||
| #685 | Redundant Connection II Depth-First SearchBreadth-First SearchUnion-FindGraph Theory | Hard | 25% | 36.4% | ||
| #1516 | Move Sub-Tree of N-Ary Tree TreeDepth-First Search | Hard | 25% | 59.8% | ||
| #1602 | Find Nearest Right Node in Binary Tree TreeBreadth-First SearchBinary Tree | Medium | 25% | 75.1% | ||
| #1612 | Check If Two Expression Trees are Equivalent Hash TableTreeDepth-First SearchBinary TreeCounting | Medium | 25% | 71.8% | ||
| #1660 | Correct a Binary Tree Hash TableTreeDepth-First SearchBreadth-First SearchBinary Tree | Medium | 25% | 74.3% | ||
| #1666 | Change the Root of a Binary Tree TreeDepth-First SearchBinary Tree | Medium | 25% | 75.0% | ||
| #1766 | Tree of Coprimes ArrayMathTreeDepth-First SearchNumber Theory | Hard | 25% | 44.4% | ||
| #1858 | Longest Word With All Prefixes ArrayStringDepth-First SearchTrie | Medium | 25% | 72.1% | ||
| #2313 | Minimum Flips in Binary Tree to Get Result Dynamic ProgrammingTreeDepth-First SearchBinary Tree | Hard | 25% | 57.0% | ||
| #2689 | Extract Kth Character From The Rope Tree TreeDepth-First SearchBinary Tree | Easy | 25% | 73.3% | ||
| #2925 | Maximum Score After Applying Operations on a Tree Dynamic ProgrammingTreeDepth-First SearchDP on Trees | Medium | 25% | 47.5% | ||
| #3493 | Properties Graph ArrayHash TableDepth-First SearchBreadth-First SearchUnion-FindGraph Theory | Medium | 13% | 49.1% | ||
| #3585 | Find Weighted Median Node in Tree ArrayBinary SearchDynamic ProgrammingBit ManipulationTreeDepth-First Search | Hard | 13% | 26.2% | ||
| #3319 | K-th Largest Perfect Subtree Size in Binary Tree TreeDepth-First SearchSortingBinary Tree | Medium | 13% | 62.4% | ||
| #3486 | Longest Special Path II ArrayHash TableTreeDepth-First SearchPrefix Sum | Hard | 13% | 19.8% | ||
| #2277 | Closest Node to Path in Tree ArrayTreeDepth-First SearchBreadth-First Search | Hard | 13% | 62.5% | ||
| #499 | The Maze III ArrayStringDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest PathDijkstra's AlgorithmHeuristic SearchA* Search | Hard | 13% | 52.5% |
Showing 353 of 353 problems in Tree Depth-First Search (DFS)Filtered: All Companies