Find Paths in Binary Tree
Kevin has sketched a series of integers, forming a diagram that represents a binary tree. Challenged by a friend, Kevin needs to find all paths from the root to the leaf where the sum equals a given number 'K'. Due to other commitments, he requests your assistance in completing this task.
Example:
Input:
If the tree structure is:
For K = 15
Output:
Paths are [5, 6, 4] and [5, 15, -5]
Explanation:
The paths starting at the root and ending at a leaf that add up to 15 are identified.
Constraints:
- 1 <= T <= 10
- 1 <= N <= 103
- -105 <= K <= 105
- -105 <= DATA <= 104
Time Limit:
1 second
Note:
You need to implement the provided function only as the other parts such as printing are already handled. Follow the input format carefully and make sure paths are in the correct format: enclosed in square brackets and separated by spaces in the output.
Be the first one to answer
Add answer anonymously...
Media.net Software Services (India) Software Developer interview questions & answers
A Software Developer was asked Q. Given a sequence of positive numbers, make it a non-decreasing sequence. Operati...read more
A Software Developer was asked Q. Interleaving Two Strings Problem Statement You are given three strings 'A', 'B',...read more
A Software Developer was asked Q. Boxes of Power Problem Statement Given a set of boxes represented by an array ga...read more
Popular interview questions of Software Developer
A Software Developer was asked Q1. Given a sequence of positive numbers, make it a non-decreasing sequence. Operati...read more
A Software Developer was asked Q2. Interleaving Two Strings Problem Statement You are given three strings 'A', 'B',...read more
A Software Developer was asked Q3. Boxes of Power Problem Statement Given a set of boxes represented by an array ga...read more
>
Media.net Software Services (India) Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

