Pattern
Tree
A compact view of archive entries grouped by recurring technique.
95 entries
95 entries tagged as Tree.
12.03.2026
hard3600. Maximize Spanning Tree Stability with Upgrades
Max of min values in span tree of graph, 2 s at most k
24.02.2026
easy1022. Sum of Root To Leaf Binary Numbers
Sum of a binary numbers in a binary tree
11.02.2026
hard3721. Longest Balanced Subarray II
Max subarray evens count = odds count tree
09.02.2026
medium1382. Balance a Binary Search Tree
Balance binary search tree
08.02.2026
easy110. Balanced Binary Tree
Is tree balanced?
07.01.2026
medium1339. Maximum Product of Splitted Binary Tree
Max sumA sumB of a tree split
06.01.2026
medium1161. Maximum Level Sum of a Binary Tree
Min level max sum in tree
16.12.2025
hard3562. Maximum Profit from Trading Stocks with Discounts
Max profit in a tree
6.08.2025
medium3479. Fruits Into Baskets III
Place fruits left to right to first available bucket tree
24.07.2025
hard2322. Minimum Score After Removals on a Tree
Min(max group xor - min group xor) by removing 2 edges from tree
20.07.2025
hard1948. Delete Duplicate Folders in System
Remove duplicate folder trees
09.06.2025
hard440. K-th Smallest in Lexicographical Order
k-th lexicographical number of 1..n
23.05.2025
hard3068. Find the Maximum Sum of Node Values
Max sum by k-xoring edges
15.04.2025
hard2179. Count Good Triplets in an Array
Triplets in same order in both (0..n)-arrays
04.04.2025
medium1123. Lowest Common Ancestor of Deepest Leaves
Lowest common ancestor of deepest tree nodes
24.02.2025
medium2467. Most Profitable Path in a Tree
Max Alice path down, Bob up in tree
23.02.2025
medium889. Construct Binary Tree from Preorder and Postorder Traversal
Tree from preorder & postorder
22.02.2025
hard1028. Recover a Tree From Preorder Traversal
Recover binary tree from depth-dashes string
21.02.2025
medium1261. Find Elements in a Contaminated Binary Tree
Is number in a tree 2 v+(1L, 2R)?
30.12.2024
medium2466. Count Ways To Build Good Strings
Ways to make 01-string length of low..high programming
25.12.2024
medium515. Find Largest Value in Each Tree Row
Tree layers maxes
24.12.2024
hard3203. Find Minimum Diameter After Merging Two Trees
Diameter of 2 connected trees
23.12.2024
medium2471. Minimum Number of Operations to Sort a Binary Tree by Level
Min swaps to sort tree layers
20.12.2024
medium2415. Reverse Odd Levels of Binary Tree
Odd-levels reversal in a perfect tree
14.12.2024
medium2762. Continuous Subarrays
Count subarrays with difference <= 2 queue set
26.10.2024
hard2458. Height of Binary Tree After Subtree Removal Queries
n new heights by cutting nodes in a Tree
23.10.2024
medium2641. Cousins in Binary Tree II
Replace Tree's values with cousines sum
22.10.2024
medium2583. Kth Largest Sum in a Binary Tree
kth largest level-sum in a tree
13.10.2024
hard632. Smallest Range Covering Elements from K Lists
Smallest intersection of k sorted lists set
19.09.2024
medium241. Different Ways to Add Parentheses
Eval all possible parenthesis placements programming
07.09.2024
medium1367. Linked List in Binary Tree
Is the LinkedList in the BinaryTree? list
26.08.2024
easy590. N-ary Tree Postorder Traversal
Postorder tree traversal
25.08.2024
easy145. Binary Tree Postorder Traversal
Postorder tree traversal tree
21.08.2024
hard664. Strange Printer
Minimum continuous replacements to make a string programming
18.07.2024
medium1530. Number of Good Leaf Nodes Pairs
Count at most distance paths between leaves
17.07.2024
medium1110. Delete Nodes And Return Forest
Trees after remove nodes from tree
16.07.2024
medium2096. Step-By-Step Directions From a Binary Tree Node to Another
U-L-R path from s to d in a Binary Tree
15.07.2024
medium2196. Create Binary Tree From Descriptions
Restore binary tree from [parent, child, isLeft]
26.06.2024
medium1382. Balance a Binary Search Tree
Make a balanced Binary Search Tree
25.06.2024
medium1038. Binary Search Tree to Greater Sum Tree
Aggregate Binary Search Tree from the right
19.05.2024
hard3068. Find the Maximum Sum of Node Values
Max sum after xor k any edges in a tree
18.05.2024
medium979. Distribute Coins in Binary Tree
Min moves to spread the coins across the tree
17.05.2024
easy1325. Delete Leaves With a Given Value
Recursively remove target leafs from the tree
16.05.2024
easy2331. Evaluate Boolean Binary Tree
Evaluate tree where 0/1 is false/true and 2/3 is or/and
28.04.2024
hard834. Sum of Distances in Tree
Sums of paths to each leafs in a tree
24.04.2024
easy1137. N-th Tribonacci Number
nth Tribonacci number f(n + 3) = f(n) + f(n + 1) + f(n + 2)
17.04.2024
medium988. Smallest String Starting From Leaf
Smallest string from leaf to root in a Binary Tree
16.04.2024
medium623. Add One Row to Tree
Insert nodes at the depth of the Binary Tree
15.04.2024
medium129. Sum Root to Leaf Numbers
Sum root-leaf numbers in a Binary Tree
14.04.2024
easy404. Sum of Left Leaves
Left-leaf sum in a Binary Tree
29.02.2024
medium1609. Even Odd Tree
Binary tree levels are odd increasing and even decreasing.
28.02.2024
medium513. Find Bottom Left Tree Value
Leftmost node value of the last level of the Binary Tree.
27.02.2024
easy543. Diameter of Binary Tree
Max distance between any nodes in binary tree.
26.02.2024
easy100. Same Tree
Are two binary trees equal?
24.01.2024
medium1457. Pseudo-Palindromic Paths in a Binary Tree
Count can-form-a-palindrome paths root-leaf in a binary tree.
11.01.2024
medium1026. Maximum Difference Between Node and Ancestor
Max diff between node and ancestor in a binary tree.
10.01.2024
medium2385. Amount of Time for Binary Tree to Be Infected
Max distance from node in a Binary Tree.
8.01.2024
easy938. Range Sum of BST
Sum of BST in range [low..high].
09.12.2023
easy94. Binary Tree Inorder Traversal
Inorder traversal
08.12.2023
easy606. Construct String from Binary Tree
Pre-order binary tree serialization
02.11.2023
medium2265. Count Nodes Equal to Average of Subtree
Number of nodes in a tree where val == sum / count of a subtree
01.11.2023
easy501. Find Mode in Binary Search Tree
Most frequent elements in a Binary Search Tree
25.10.2023
medium779. K-th Symbol in Grammar
Binary Tree 0 -> 01, 1 -> 10 at [n][k] position
24.10.2023
medium515. Find Largest Value in Each Tree Row
Binary Tree's maxes of the levels
17.10.2023
medium1361. Validate Binary Tree Nodes
Is Binary Tree of leftChild[] & rightChild[] valid
19.08.2023
hard1489. Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree
List of list of must-have edges and list of optional edges for Minimum Weight Minimum Spanning Tree
05.08.2023
medium95. Unique Binary Search Trees II
All possible Binary Search Trees for 1..n numbers
23.07.2023
medium894. All Possible Full Binary Trees
All possible Full Binary Trees with n nodes, each have both children
12.07.2023
medium863. All Nodes Distance K in Binary Tree
List of k distanced from target nodes in a Binary Tree
11.07.2023
easy111. Minimum Depth of Binary Tree
Count nodes in the shortest path from root to leaf
16.06.2023
hard1569. Number of Ways to Reorder Array to Get Same BST
Count permutations of an array with identical Binary Search Tree
15.06.2023
medium1161. Maximum Level Sum of a Binary Tree
Binary Tree level with max sum
14.06.2023
easy530. Minimum Absolute Difference in BST
Min difference in a BST
20.04.2023
medium662. Maximum Width of Binary Tree
We can do BFS and track node positions.
19.04.2023
medium1372. Longest ZigZag Path in a Binary Tree
Compute the max as you go
17.03.2023
medium208. Implement Trie (Prefix Tree)
Let's try to write it Kotlin-way
16.03.2023
medium106. Construct Binary Tree from Inorder and Postorder Traversal
To more robust code, consider moving postTo variable as we go in the reverse-postorder: from the right to the left.
15.03.2023
medium958. Check Completeness of a Binary Tree
Right depth must not be larger than left.
13.03.2023
easy101. Symmetric Tree
Recursive: just write helper function.
11.03.2023
medium109. Convert Sorted List to Binary Search Tree
Compute the middle of the linked list.
28.02.2023
medium652. Find Duplicate Subtrees
Let's use pre-order traversal and serialize each node into string, also add that into HashSet and check for duplicates.
27.02.2023
medium427. Construct Quad Tree
use inclusive ranges to simplify the code
19.02.2023
medium103. Binary Tree Zigzag Level Order Traversal
for zigzag, we can skip a boolean variable and track result count.
18.02.2023
easy226. Invert Binary Tree
Let's write a recursive one-liner.
17.02.2023
easy783. Minimum Distance Between BST Nodes
Let's write Morris Traversal. Store current node at the rightmost end of the left children.
16.02.2023
easy104. Maximum Depth of Binary Tree
Let's write a one-liner.
12.01.2023
medium1519. Number of Nodes in the Sub-Tree With the Same Label
fun countSubTrees(n: Int, edges: Array
11.01.2023
medium1443. Minimum Time to Collect All Apples in a Tree
fun minTime(n: Int, edges: Array
10.01.2023
easy100. Same Tree
fun isSameTree(p: TreeNode?, q: TreeNode?): Boolean = p == null && q == null ||
9.01.2023
easy144. Binary Tree Preorder Traversal
class Solution {
22.12.2022
hard834. Sum of Distances in Tree
fun sumOfDistancesInTree(n: Int, edges: Array
11.12.2022
hard124. Binary Tree Maximum Path Sum
fun maxPathSum(root: TreeNode?): Int {
10.12.2022
medium1339. Maximum Product of Splitted Binary Tree
fun maxProduct(root: TreeNode?): Int {
7.12.2022
easy938. Range Sum of BST
fun rangeSumBST(root: TreeNode?, low: Int, high: Int): Int =
15.11.2022
mediumCount Complete Tree Nodes
x