GREEDY PICK

Given a binary tree of integers.

Return the maximum value you can pick from nodes of given binary tree without picking any pair of nodes which are directly linked i.e. if you picked some node you cannot pick its children nodes

As answer can be very large return answer %10^9 + 7

Constraints

1 <= Number of nodes in binary tree <= 100000
0 <= node values <= 10^9 

For Example

Input 1:
            3
          /   \
         2    3
          \    \
           3    1
      
Output 1:
    7
Explaination 1:
    Only nodes represented by _ are picked 
            _
          /   \
         2    3
          \    \
           -    -
        
    
Input 2:
            3
           /  \
          4    5
         / \    \
        1   3    1
Output 2:
    9
Explaination 2:
            3
           /  \
          -    -
         / \    \
        1   3    1
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 GREEDY PICK on Interview Code Editor
Sign Up
to access hints and editorial solutions for GREEDY PICK

Discussion


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