LeetCode 1302. Deepest Leaves Sum in Java

In this post we will solve the LeetCode 1302. Deepest Leaves Sum problem using the Java programming language with the VSCode IDE on a Windows computer.

Given the root of a binary tree, 
return the sum of values of its deepest leaves.

Constraints:

o The number of nodes in the tree is in the range [1, 10^4].
o 1 <= Node.val <= 100

Related Topics:

o Tree
o Depth-First Search
o Breadth-First Search
o Binary Tree

We are given a binary tree and we need to return the sum of the values of all deepest leaves. Continue reading “LeetCode 1302. Deepest Leaves Sum in Java”

Find Leaf Nodes in a Tree for which the Sum of the Root Path Matches a Target Value

I did not find this problem on a website. The requirements came up during a conversation with a software engineer. I wish I could have taken some notes but I did not. The problem had a single diagram of a sample general tree and there was no class definition for the nodes.

We are given a general binary three in which a node may have none, one or more children.
In addition each node has an integer value.
The values may repeat.

Our tasks if to come up with a function 
that will display the leaf nodes 
for which the sum of all node values in the path from the root 
add up to a defined target.

As far as I can remember that was the gist of the problem. Continue reading “Find Leaf Nodes in a Tree for which the Sum of the Root Path Matches a Target Value”