type
Tree LeetCode problems — visual solutions
Every LeetCode problem tagged Tree — the full catalogue, plus animated visual solutions in Python and Go when a deep-dive exists.
364 problems · 282 animated · 82 locked
Full Tree index
- 94Binary Tree Inorder TraversalWatch
- 95Unique Binary Search Trees IIWatch
- 96Unique Binary Search TreesWatch
- 98Validate Binary Search TreeWatch
- 99Recover Binary Search TreeWatch
- 100Same TreeWatch
- 101Symmetric TreeWatch
- 102Binary Tree Level Order TraversalWatch
- 103Binary Tree Zigzag Level Order TraversalWatch
- 104Maximum Depth of Binary TreeWatch
- 105Construct Binary Tree from Preorder and Inorder TraversalWatch
- 106Construct Binary Tree from Inorder and Postorder TraversalWatch
- 107Binary Tree Level Order Traversal IIWatch
- 108Convert Sorted Array to Binary Search TreeWatch
- 109Convert Sorted List to Binary Search TreeWatch
- 110Balanced Binary TreeWatch
- 111Minimum Depth of Binary TreeWatch
- 112Path SumWatch
- 113Path Sum IIWatch
- 114Flatten Binary Tree to Linked ListWatch
- 116Populating Next Right Pointers in Each NodeWatch
- 117Populating Next Right Pointers in Each Node IIWatch
- 124Binary Tree Maximum Path SumWatch
- 129Sum Root to Leaf NumbersWatch
- 144Binary Tree Preorder TraversalWatch
- 145Binary Tree Postorder TraversalWatch
- 156Binary Tree Upside DownLocked
- 173Binary Search Tree IteratorWatch
- 199Binary Tree Right Side ViewWatch
- 218The Skyline ProblemWatch
- 222Count Complete Tree NodesWatch
- 226Invert Binary TreeWatch
- 230Kth Smallest Element in a BSTWatch
- 235Lowest Common Ancestor of a Binary Search TreeWatch
- 236Lowest Common Ancestor of a Binary TreeWatch
- 250Count Univalue SubtreesLocked
- 255Verify Preorder Sequence in Binary Search TreeLocked
- 257Binary Tree PathsWatch
- 270Closest Binary Search Tree ValueLocked
- 272Closest Binary Search Tree Value IILocked
- 285Inorder Successor in BSTLocked
- 297Serialize and Deserialize Binary TreeWatch
- 298Binary Tree Longest Consecutive SequenceLocked
- 307Range Sum Query - MutableWatch
- 308Range Sum Query 2D - MutableLocked
- 314Binary Tree Vertical Order TraversalLocked
- 315Count of Smaller Numbers After SelfWatch
- 327Count of Range SumWatch
- 331Verify Preorder Serialization of a Binary TreeWatch
- 333Largest BST SubtreeLocked
- 337House Robber IIIWatch
- 341Flatten Nested List IteratorWatch
- 366Find Leaves of Binary TreeLocked
- 404Sum of Left LeavesWatch
- 406Queue Reconstruction by HeightWatch
- 426Convert Binary Search Tree to Sorted Doubly Linked ListLocked
- 427Construct Quad TreeWatch
- 428Serialize and Deserialize N-ary TreeLocked
- 429N-ary Tree Level Order TraversalWatch
- 431Encode N-ary Tree to Binary TreeLocked
- 437Path Sum IIIWatch
- 449Serialize and Deserialize BSTWatch
- 450Delete Node in a BSTWatch
- 493Reverse PairsWatch
- 501Find Mode in Binary Search TreeWatch
- 508Most Frequent Subtree SumWatch
- 510Inorder Successor in BST IILocked
- 513Find Bottom Left Tree ValueWatch
- 515Find Largest Value in Each Tree RowWatch
- 530Minimum Absolute Difference in BSTWatch
- 536Construct Binary Tree from StringLocked
- 538Convert BST to Greater TreeWatch
- 543Diameter of Binary TreeWatch
- 545Boundary of Binary TreeLocked
- 549Binary Tree Longest Consecutive Sequence IILocked
- 558Logical OR of Two Binary Grids Represented as Quad-TreesWatch
- 559Maximum Depth of N-ary TreeWatch
- 563Binary Tree TiltWatch
- 572Subtree of Another TreeWatch
- 582Kill ProcessLocked
- 589N-ary Tree Preorder TraversalWatch
- 590N-ary Tree Postorder TraversalWatch
- 606Construct String from Binary TreeWatch
- 617Merge Two Binary TreesWatch
- 623Add One Row to TreeWatch
- 637Average of Levels in Binary TreeWatch
- 652Find Duplicate SubtreesWatch
- 653Two Sum IV - Input is a BSTWatch
- 654Maximum Binary TreeWatch
- 655Print Binary TreeWatch
- 662Maximum Width of Binary TreeWatch
- 663Equal Tree PartitionLocked
- 666Path Sum IVLocked
- 669Trim a Binary Search TreeWatch
- 671Second Minimum Node In a Binary TreeWatch
- 673Number of Longest Increasing SubsequenceWatch
- 683K Empty SlotsLocked
- 687Longest Univalue PathWatch
- 690Employee ImportanceWatch
- 699Falling SquaresWatch
- 700Search in a Binary Search TreeWatch
- 701Insert into a Binary Search TreeWatch
- 703Kth Largest Element in a StreamWatch
- 715Range ModuleWatch
- 729My Calendar IWatch
- 731My Calendar IIWatch
- 732My Calendar IIIWatch
- 742Closest Leaf in a Binary TreeLocked
- 776Split BSTLocked
- 783Minimum Distance Between BST NodesWatch
- 814Binary Tree PruningWatch
- 834Sum of Distances in TreeWatch
- 850Rectangle Area IIWatch
- 863All Nodes Distance K in Binary TreeWatch
- 865Smallest Subtree with all the Deepest NodesWatch
- 872Leaf-Similar TreesWatch
- 889Construct Binary Tree from Preorder and Postorder TraversalWatch
- 894All Possible Full Binary TreesWatch
- 897Increasing Order Search TreeWatch
- 919Complete Binary Tree InserterWatch
- 938Range Sum of BSTWatch
- 951Flip Equivalent Binary TreesWatch
- 958Check Completeness of a Binary TreeWatch
- 965Univalued Binary TreeWatch
- 968Binary Tree CamerasWatch
- 971Flip Binary Tree To Match Preorder TraversalWatch
- 979Distribute Coins in Binary TreeWatch
- 987Vertical Order Traversal of a Binary TreeWatch
- 988Smallest String Starting From LeafWatch
- 993Cousins in Binary TreeWatch
- 998Maximum Binary Tree IIWatch
- 1008Construct Binary Search Tree from Preorder TraversalWatch
- 1022Sum of Root To Leaf Binary NumbersWatch
- 1026Maximum Difference Between Node and AncestorWatch
- 1028Recover a Tree From Preorder TraversalWatch
- 1038Binary Search Tree to Greater Sum TreeWatch
- 1080Insufficient Nodes in Root to Leaf PathsWatch
- 1104Path In Zigzag Labelled Binary TreeWatch
- 1110Delete Nodes And Return ForestWatch
- 1120Maximum Average SubtreeLocked
- 1123Lowest Common Ancestor of Deepest LeavesWatch
- 1145Binary Tree Coloring GameWatch
- 1157Online Majority Element In SubarrayWatch
- 1161Maximum Level Sum of a Binary TreeWatch
- 1214Two Sum BSTsLocked
- 1245Tree DiameterLocked
- 1257Smallest Common RegionLocked
- 1261Find Elements in a Contaminated Binary TreeWatch
- 1273Delete Tree NodesLocked
- 1302Deepest Leaves SumWatch
- 1305All Elements in Two Binary Search TreesWatch
- 1315Sum of Nodes with Even-Valued GrandparentWatch
- 1325Delete Leaves With a Given ValueWatch
- 1339Maximum Product of Splitted Binary TreeWatch
- 1361Validate Binary Tree NodesWatch
- 1367Linked List in Binary TreeWatch
- 1372Longest ZigZag Path in a Binary TreeWatch
- 1373Maximum Sum BST in Binary TreeWatch
- 1376Time Needed to Inform All EmployeesWatch
- 1377Frog Position After T SecondsWatch
- 1379Find a Corresponding Node of a Binary Tree in a Clone of That TreeWatch
- 1382Balance a Binary Search TreeWatch
- 1395Count Number of TeamsWatch
- 1409Queries on a Permutation With KeyWatch
- 1430Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary TreeLocked
- 1443Minimum Time to Collect All Apples in a TreeWatch
- 1448Count Good Nodes in Binary TreeWatch
- 1457Pseudo-Palindromic Paths in a Binary TreeWatch
- 1469Find All The Lonely NodesLocked
- 1483Kth Ancestor of a Tree NodeWatch
- 1485Clone Binary Tree With Random PointerLocked
- 1490Clone N-ary TreeLocked
- 1505Minimum Possible Integer After at Most K Adjacent Swaps On DigitsWatch
- 1506Find Root of N-Ary TreeLocked
- 1516Move Sub-Tree of N-Ary TreeLocked
- 1519Number of Nodes in the Sub-Tree With the Same LabelWatch
- 1521Find a Value of a Mysterious Function Closest to TargetWatch
- 1522Diameter of N-Ary TreeLocked
- 1530Number of Good Leaf Nodes PairsWatch
- 1569Number of Ways to Reorder Array to Get Same BSTWatch
- 1586Binary Search Tree Iterator IILocked
- 1597Build Binary Expression Tree From Infix ExpressionLocked
- 1600Throne InheritanceWatch
- 1602Find Nearest Right Node in Binary TreeLocked
- 1609Even Odd TreeWatch
- 1612Check If Two Expression Trees are EquivalentLocked
- 1617Count Subtrees With Max Distance Between CitiesWatch
- 1622Fancy SequenceWatch
- 1628Design an Expression Tree With Evaluate FunctionLocked
- 1644Lowest Common Ancestor of a Binary Tree IILocked
- 1649Create Sorted Array through InstructionsWatch
- 1650Lowest Common Ancestor of a Binary Tree IIILocked
- 1660Correct a Binary TreeLocked
- 1666Change the Root of a Binary TreeLocked
- 1676Lowest Common Ancestor of a Binary Tree IVLocked
- 1687Delivering Boxes from Storage to PortsWatch
- 1719Number Of Ways To Reconstruct A TreeWatch
- 1740Find Distance in a Binary TreeLocked
- 1766Tree of CoprimesWatch
- 1902Depth of BST Given Insertion OrderLocked
- 1916Count Ways to Build Rooms in an Ant ColonyWatch
- 1932Merge BSTs to Create Single BSTWatch
- 1964Find the Longest Valid Obstacle Course at Each PositionWatch
- 1973Count Nodes Equal to Sum of DescendantsLocked
- 1993Operations on TreeWatch
- 2003Smallest Missing Genetic Value in Each SubtreeWatch
- 2005Subtree Removal Game with Fibonacci TreeLocked
- 2031Count Subarrays With More Ones Than ZerosLocked
- 2049Count Nodes With the Highest ScoreWatch
- 2080Range Frequency QueriesWatch
- 2096Step-By-Step Directions From a Binary Tree Node to AnotherWatch
- 2158Amount of New Area Painted Each DayLocked
- 2179Count Good Triplets in an ArrayWatch
- 2193Minimum Number of Moves to Make PalindromeWatch
- 2196Create Binary Tree From DescriptionsWatch
- 2213Longest Substring of One Repeating CharacterWatch
- 2236Root Equals Sum of ChildrenWatch
- 2246Longest Path With Different Adjacent CharactersWatch
- 2250Count Number of Rectangles Containing Each PointWatch
- 2265Count Nodes Equal to Average of SubtreeWatch
- 2276Count Integers in IntervalsWatch
- 2277Closest Node to Path in TreeLocked
- 2286Booking Concert Tickets in GroupsWatch
- 2313Minimum Flips in Binary Tree to Get ResultLocked
- 2322Minimum Score After Removals on a TreeWatch
- 2331Evaluate Boolean Binary TreeWatch
- 2368Reachable Nodes With RestrictionsWatch
- 2378Choose Edges to Maximize Score in a TreeLocked
- 2385Amount of Time for Binary Tree to Be InfectedWatch
- 2407Longest Increasing Subsequence IIWatch
- 2415Reverse Odd Levels of Binary TreeWatch
- 2421Number of Good PathsWatch
- 2424Longest Uploaded PrefixWatch
- 2426Number of Pairs Satisfying InequalityWatch
- 2440Create Components With Same ValueWatch
- 2445Number of Nodes With Value OneLocked
- 2458Height of Binary Tree After Subtree Removal QueriesWatch
- 2467Most Profitable Path in a TreeWatch
- 2471Minimum Number of Operations to Sort a Binary Tree by LevelWatch
- 2476Closest Nodes Queries in a Binary Search TreeWatch
- 2477Minimum Fuel Cost to Report to the CapitalWatch
- 2479Maximum XOR of Two Non-Overlapping SubtreesLocked
- 2509Cycle Length Queries in a TreeWatch
- 2519Count the Number of K-Big IndicesLocked
- 2538Difference Between Maximum and Minimum Price SumWatch
- 2552Count Increasing QuadrupletsWatch
- 2569Handling Sum Queries After UpdateWatch
- 2581Count Number of Possible Root NodesWatch
- 2583Kth Largest Sum in a Binary TreeWatch
- 2603Collect Coins in a TreeWatch
- 2641Cousins in Binary Tree IIWatch
- 2646Minimize the Total Price of the TripsWatch
- 2659Make Array EmptyWatch
- 2673Make Costs of Paths Equal in a Binary TreeWatch
- 2689Extract Kth Character From The Rope TreeLocked
- 2736Maximum Sum QueriesWatch
- 2764Is Array a Preorder of Some Binary TreeLocked
- 2773Height of Special Binary TreeLocked
- 2791Count Paths That Can Form a Palindrome in a TreeWatch
- 2792Count Nodes That Are Great EnoughLocked
- 2846Minimum Edge Weight Equilibrium Queries in a TreeWatch
- 2867Count Valid Paths in a TreeWatch
- 2872Maximum Number of K-Divisible ComponentsWatch
- 2907Maximum Profitable Triplets With Increasing Prices ILocked
- 2913Subarrays Distinct Element Sum of Squares IWatch
- 2916Subarrays Distinct Element Sum of Squares IIWatch
- 2920Maximum Points After Collecting Coins From All NodesWatch
- 2921Maximum Profitable Triplets With Increasing Prices IILocked
- 2925Maximum Score After Applying Operations on a TreeWatch
- 2926Maximum Balanced Subsequence SumWatch
- 2940Find Building Where Alice and Bob Can MeetWatch
- 2973Find Number of Coins to Place in Tree NodesWatch
- 3004Maximum Subtree of the Same ColorLocked
- 3009Maximum Number of Intersections on the ChartLocked
- 3067Count Pairs of Connectable Servers in a Weighted Tree NetworkWatch
- 3068Find the Maximum Sum of Node ValuesWatch
- 3072Distribute Elements Into Two Arrays IIWatch
- 3109Find the Index of PermutationLocked
- 3117Minimum Sum of Values by Dividing ArrayWatch
- 3157Find the Level of Tree with Minimum SumLocked
- 3161Block Placement QueriesWatch
- 3165Maximum Sum of Subsequence With Non-adjacent ElementsWatch
- 3171Find Subarray With Bitwise OR Closest to KWatch
- 3187Peaks in ArrayWatch
- 3203Find Minimum Diameter After Merging Two TreesWatch
- 3209Number of Subarrays With AND Value of KWatch
- 3241Time Taken to Mark All NodesWatch
- 3245Alternating Groups IIIWatch
- 3249Count the Number of Good NodesWatch
- 3291Minimum Number of Valid Strings to Form Target IWatch
- 3292Minimum Number of Valid Strings to Form Target IIWatch
- 3313Find the Last Marked Nodes in TreeLocked
- 3319K-th Largest Perfect Subtree Size in Binary TreeWatch
- 3327Check if DFS Strings Are PalindromesWatch
- 3331Find Subtree Sizes After ChangesWatch
- 3367Maximize Sum of Weights after Edge RemovalsWatch
- 3372Maximize the Number of Target Nodes After Connecting Trees IWatch
- 3373Maximize the Number of Target Nodes After Connecting Trees IIWatch
- 3380Maximum Area Rectangle With Point Constraints IWatch
- 3382Maximum Area Rectangle With Point Constraints IIWatch
- 3410Maximize Subarray Sum After Removing All Occurrences of One ElementWatch
- 3420Count Non-Decreasing Subarrays After K OperationsWatch
- 3425Longest Special PathWatch
- 3454Separate Squares IIWatch
- 3477Fruits Into Baskets IIWatch
- 3479Fruits Into Baskets IIIWatch
- 3480Maximize Subarrays After Removing One Conflicting PairWatch
- 3486Longest Special Path IIWatch
- 3501Maximize Active Section with Trade IIWatch
- 3515Shortest Path in a Weighted TreeWatch
- 3520Minimum Threshold for Inversion Pairs CountLocked
- 3525Find X Value of Array IIWatch
- 3526Range XOR Queries with Subarray ReversalsLocked
- 3544Subtree Inversion SumWatch
- 3553Minimum Weighted Subgraph With the Required Paths IIWatch
- 3558Number of Ways to Assign Edge Weights IWatch
- 3559Number of Ways to Assign Edge Weights IIWatch
- 3562Maximum Profit from Trading Stocks with DiscountsWatch
- 3569Maximize Count of Distinct Primes After SplitWatch
- 3575Maximum Good Subtree ScoreWatch
- 3585Find Weighted Median Node in TreeWatch
- 3590Kth Smallest Path XOR SumWatch
- 3593Minimum Increments to Equalize Leaf PathsWatch
- 3605Minimum Stability Factor of ArrayWatch
- 3624Number of Integers With Popcount-Depth Equal to K IIWatch
- 3671Sum of Beautiful SubsequencesWatch
- 3691Maximum Total Subarray Value IIWatch
- 3715Sum of Perfect Square AncestorsWatch
- 3719Longest Balanced Subarray IWatch
- 3721Longest Balanced Subarray IIWatch
- 3737Count Subarrays With Majority Element IWatch
- 3739Count Subarrays With Majority Element IIWatch
- 3762Minimum Operations to Equalize SubarraysWatch
- 3768Minimum Inversion Count in Subarrays of Fixed LengthWatch
- 3772Maximum Subgraph Score in a TreeWatch
- 3777Minimum Deletions to Make Alternating SubstringWatch
- 3786Total Sum of Interaction Cost in Tree GroupsWatch
- 3787Find Diameter Endpoints of a TreeLocked
- 3812Minimum Edge Toggles on a TreeWatch
- 3820Pythagorean Distance Nodes in a TreeWatch
- 3831Median of a Binary Search Tree LevelLocked
- 3841Palindromic Path Queries in a TreeWatch
- 3879Maximum Distinct Path Sum in a Binary TreeLocked
- 3901Good Subsequence QueriesWatch
- 3902Zigzag Level Sum of Binary TreeLocked
- 3915Maximum Sum of Alternating Subsequence With Distance at Least KWatch
- 3930Power Update After K-th Largest Insertion IILocked
- 3935Power Update After K-th Largest Insertion ILocked
- 3939Count Non Adjacent Subsets in a Rooted TreeWatch
- 3949Subtree Inversion Sum IILocked
- 3962Maximum Subarray Sum After at Most K SwapsWatch
- 3965Finish Time of Tasks IWatch
- 3967Finish Time of Tasks IILocked
- 3973Distinct Gate Paths to LCALocked
- 3997Count Dominant Nodes in a Binary TreeWatch
- 4011Count Subarrays With Even Odd Ratio IWatch
- 4013Count Subarrays With Even Odd Ratio IIWatch
- 4015Weighted Sum of a TreeWatch
- 4017Peaks in Array IIWatch
- 4018Total Sum of Interaction Cost in Tree Groups IILocked
- 4033Valid K-Unique Subarrays IWatch
- 4042Valid K-Unique Subarrays IILocked
- 4051Count Subarrays with Distant SumsWatch
- 4055Count Shadow Pairs IIWatch