Height, Path, Views
Height
104. Maximum Depth of Binary Tree
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. An empty tree has depth 0, a single node has depth 1.
111. Minimum Depth of Binary Tree
Find the minimum depth from the root to any leaf node. The minimum depth is the shortest path from root to leaf.
Path
112. Path Sum
112Path Sum
Determine if a binary tree has a root-to-leaf path whose sum equals the given target value. A leaf is a node with no children.
113. Path Sum II
113Path Sum II
Find all root-to-leaf paths where the sum equals the target value. Return all valid paths as a list of lists containing node values.
257. Binary Tree Paths
Return all root-to-leaf paths in a binary tree as strings, where each path shows the values connected by "->".
129. Sum Root to Leaf Numbers
Each root-to-leaf path spells a decimal number (most significant digit at the root). Carry the running value down with cur_decimal = 10 * cur_decimal + node.val, and add it to the total whenever a leaf is reached. This mirrors the binary version (1022), swapping base 2 for base 10.
1022. Sum of Root To Leaf Binary Numbers
Each root-to-leaf path spells a binary number (most significant bit at the root). Carry the running value down the path with cur_binary = 2 * cur_binary + node.val, and add it to the total whenever a leaf is reached.
988. Smallest String Starting From Leaf
Each node value 0..25 maps to a letter via chr(ord('a') + node.val). Walk root-to-leaf collecting letters, and at every leaf reverse the collected path to get the leaf-to-root word. Keep the lexicographically smallest word seen.
1457. Pseudo-Palindromic Paths in a Binary Tree
A root-to-leaf path is pseudo-palindromic if its node values can be rearranged into a palindrome - which happens exactly when at most one digit value appears an odd number of times. Track parity with a bitmask: toggle bit node.val on each step (path ^ (1 << node.val)). At a leaf the path is valid when the mask has at most one bit set, i.e. path & (path - 1) == 0.
1026. Maximum Difference Between Node and Ancestor
The largest |ancestor - descendant| along any root-to-node path equals max - min of the values on that path. Carry the running max_node and min_node down each path; the answer at any point is abs(max_node - min_node), and the overall answer is the largest such value across all paths.
1448. Count Good Nodes in Binary Tree
A node is good when nothing on the path from the root down to it is strictly larger. Only the running maximum of that path matters, so carry maxi down as you descend and compare each node against it. Ties count: the test is node.val >= maxi.
1430. Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree
Decide whether arr spells out a complete root-to-leaf path. Two things must hold together: the values have to match level by level from the root, and the run has to end exactly on a leaf at arr's last index - a matching prefix that stops mid-tree, or a leaf reached too early, is not valid.
Views
Left View of Binary Tree
The left view of a binary tree is the set of nodes visible when the tree is viewed from the left side. In other words, it's the first node at each level when traversing from left to right.
Right View of Binary Tree
The right view of a binary tree is the set of nodes visible when the tree is viewed from the right side. In other words, it's the last node at each level when traversing from left to right.
Top View of Binary Tree
The top view of a binary tree is the set of nodes visible when the tree is viewed from the top. Each column position should show only the topmost node (closest to root level).
Bottom View of Binary Tree
The bottom view of a binary tree is the set of nodes visible when the tree is viewed from the bottom. Each column position should show only the bottommost node (farthest from root level).
545. Boundary of Binary Tree
The boundary of a binary tree is the concatenation of root, left boundary, leaves, and right boundary in counter-clockwise direction.
- Left boundary: path from root to the left-most node
- Right boundary: path from root to the right-most node
- Leaves: all leaf nodes in left-to-right order