Binary Tree Paths

Given a binary tree. Return all root to leaf paths.

You can return the paths in any order.

Note: A leaf is a node with no children.

For Example

Input 1:
                57
               /  \
              77  76
             / \ 
            21  16
Output 1:
    [   [57, 76]
        [57, 77, 16]
        [57, 77, 21]    ] 

Input 2:
                1
               / \
              2   3
             / \  / \
            4   5 6  7
Output 2:
     [  [1, 2, 4]
        [1, 2, 5]
        [1, 3, 6]
        [1, 3, 7]    ] 
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 Binary Tree Paths on Interview Code Editor
Sign Up
to access hints and editorial solutions for Binary Tree Paths

Discussion


Loading...
Click here to start solving coding interview questions