You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Question: Given a binary tree, find a subtree such that the sum of all the nodes in the subtree add up to a number N. If there are multiple subtrees satisfying this criteria, return any one. If there is no subtree that meets the criteria, return an empty tree.
Example 1: Input: Tree = [1, 2, 3, 4, 5, 6, 7, 8, 9, null, 10, null, 12, null,
null], N = 21
Output: [4, 8, 9]
The given input array represents the following tree:
1
/ \
2 3
/ \ / \
4 5 6 7
/ \ \ \
8 9 10 12
Example 2: Input: Tree = [2, 7, 6], N = 12
Output: []
The given input array represents the following tree:
2
/ \
7 6
Example 3: Input: Tree = [2, 7, 6], N = 9
Output: [2, 7]
The text was updated successfully, but these errors were encountered:
Question: Given a binary tree, find a subtree such that the sum of all the nodes in the subtree add up to a number N. If there are multiple subtrees satisfying this criteria, return any one. If there is no subtree that meets the criteria, return an empty tree.
The text was updated successfully, but these errors were encountered: