Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem Submissions: Trees #189

Open
aaditkamat opened this issue Jan 18, 2019 · 2 comments
Open

Problem Submissions: Trees #189

aaditkamat opened this issue Jan 18, 2019 · 2 comments
Assignees
Labels
assigned enhancement New feature or request Hacktoberfest question Further information is requested

Comments

@aaditkamat
Copy link
Contributor

aaditkamat commented Jan 18, 2019

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]
@MadhavBahl
Copy link
Member

Good one, Feel free to add it to the repo in the bonus section and send a PR 😃

@MadhavBahl MadhavBahl added enhancement New feature or request question Further information is requested assigned labels Jan 20, 2019
@NormalVad
Copy link

Hi @MadhavBahl , I would like to work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assigned enhancement New feature or request Hacktoberfest question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants