Given the root of a binary tree, calculate the sum of all leaf nodes that are located at an odd depth. The root node is considered to be at depth 1, its immediate children are at depth 2, their children are at depth 3, and so forth. A leaf node is defined as a node with no children.
Explanation: The leaf nodes in this tree are 4 and 5. Node 4 is at depth 3 (odd) and Node 5 is at depth 3 (odd). The sum of these odd-depth leaf nodes is 4 + 5 = 9.
Explanation: The only leaf node is 2, which is at depth 2 (even). Since there are no leaf nodes at odd depths, the sum is 0.
Master coding challenges related to Trees and solve the Odd Depth Leaf Sum problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak