Skip to content

Problem Submissions: Trees #189

Open
@aaditkamat

Description

@aaditkamat

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]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions