Root to Leaf Paths With Sum

Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.

For example:
Given the below binary tree and sum = 22,

              5
             / \
            4   8
           /   / \
          11  13  4
         /  \    / \
        7    2  5   1

return

[
   [5,4,11,2],
   [5,8,4,5]
]
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Root to Leaf Paths With Sum on Interview Code Editor
Sign Up
to access hints and editorial solutions for Root to Leaf Paths With Sum
6385 successful submissions.
Asked In:
  • Microsoft
  • Yahoo
  • Amazon
Click here to start solving coding interview questions