Simply Traverse
Simply DFS
2236. Root Equals Sum of Children
The tree is guaranteed to hold exactly three nodes - a root with both children present - so there is nothing to traverse. Read the three values and compare.
Sum of Binary Tree
Calculate the sum of all node values in a binary tree by traversing each node and adding its value to the total sum.
Size of Binary Tree
Count the total number of nodes in a binary tree. Each node contributes 1 to the count, regardless of its value.
Count Leaves in Binary Tree
Count leaf nodes (nodes with no children) in a binary tree. A leaf node has both left and right children as null.
Count Non-Leaf Nodes in Tree
Count internal nodes (non-leaf nodes) in a binary tree. A non-leaf node has at least one child (left or right).
Sum of Leaf Nodes
Calculate the sum of all leaf node values in a binary tree. A leaf node has no children (both left and right are null).
Max and min element in Binary Tree
Find the maximum and minimum values among all nodes in a binary tree by comparing each node's value during traversal.
Vertical Width of a Binary Tree
Find the vertical width of a binary tree. The vertical width is the number of vertical columns needed to display the tree, where each node is assigned a column based on its horizontal distance from the root.
1469. Find All The Lonely Nodes
A lonely node is a node that is the only child of its parent node. Find all lonely nodes in a binary tree. The root node is never lonely as it has no parent.
965. Univalued Binary Tree
A binary tree is univalued if every node in the tree has the same value. Check if a given binary tree is univalued.
404. Sum of Left Leaves
Given the root of a binary tree, return the sum of all left leaves. A left leaf is a leaf which is the left child of another node.
1315. Sum of Nodes with Even-Valued Grandparent
Given the root of a binary tree, return the sum of values of nodes with even-valued grandparent. A grandparent is the parent of a parent of a node.
671. Second Minimum Node In a Binary Tree
Simply BFS
637. Average of Levels in Binary Tree
Given the root of a binary tree, return the average value of the nodes on each level in the form of an array.
1302. Deepest Leaves Sum
Given the root of a binary tree, return the sum of values of its deepest leaves.
1161. Maximum Level Sum of a Binary Tree
Given the root of a binary tree, return the number of the level that has the maximum sum (1-indexed).
3157. Find the Level of Tree with Minimum Sum
Given the root of a binary tree, return the number of the level that has the minimum sum (1-indexed).
Max Level Sum in Binary Tree
Find the level in a binary tree that has the maximum sum of node values. Return the maximum sum found across all levels.
Largest value in each level
Find the largest value in each level of a binary tree and return them as a list.
Sum of Leaf Nodes at Min Level
Find the minimum level where leaf nodes exist, then sum all leaf node values at that specific level. A leaf node has no left or right children.
Odd even level difference
Calculate the sum of all nodes at odd-numbered levels (1, 3, 5, ...) and subtract the sum of all nodes at even-numbered levels (2, 4, 6, ...). Root is at level 1 (odd level).
Maximum Width of Tree
Find the maximum number of nodes present at any level in a binary tree. The width of a level is the total number of nodes (including null nodes) at that level.
Maximum Node Level
Find the level in a binary tree that has the maximum number of nodes. Return the level number (0-indexed from root).
Level of a Node in Binary Tree
Find the level of a given node in a binary tree. Return the level (1-indexed from root) if the node exists, otherwise return 0.
Leaves at Same Level or Not
Check if all leaf nodes in a binary tree are at the same level. Return True if all leaves are at the same level, False otherwise.
Nodes at Odd Levels
Next Right Node
Find the next right node of a given key in a binary tree. The next right node is the node that appears immediately to the right of the given key at the same level. If there's no such node, return a node with value -1.
1609. Even Odd Tree
1609Even Odd Tree
A binary tree is named Even-Odd if it meets the following conditions:
- The root of the binary tree is at level index 0, its children are at level index 1, their children are at level index 2, etc.
- For every even-indexed level, all nodes at the level have odd integer values in strictly increasing order (from left to right).
- For every odd-indexed level, all nodes at the level have even integer values in strictly decreasing order (from left to right).
Given the root of a binary tree, return true if the binary tree is Even-Odd, otherwise return false.
513. Find Bottom Left Tree Value
Given the root of a binary tree, return the leftmost value in the last row of the tree.