Given a binary tree of N nodes, the task is to find the maximum product of the elements of any path in the binary tree.
Note: A path starts from the root and ends at any leaf in the tree.
Examples:
Input:
4
/ \
2 8
/ \ / \
2 1 3 4Output: 128
Explanation: Path in the given tree goes like {4, 8, 4} which gives the max score of 4 x 8 x 4 = 128.Input:
10
/ \
7 5
\
1Output: 70
Explanation: The path {10, 7} gives a score of 70 which is the maximum possible.
Approach: The idea to solve the problem is by using DFS traversal of a tree using recursion.
For every node recursively find the maximum product of left subtree and right substree of that node and return the product of that value with the node’s data.
Follow the steps mentioned below to solve the problem
 As the base Condition. If the root is NULL, simply return 1.
 Call the recursive function for the left and right subtrees to get the maximum product from both the subtrees.
 Return the value of the current node multiplied by the maximum product out of the left and right subtree as the answer of the current recursion.
Below is the implementation of the above approach.
C++

Time Complexity: O(N).
Auxiliary Space: O( Height of the tree)