Given a tree with 'n' nodes, where each node has a value, find the product of all values in the subtree rooted at each node and return the maximum product. The tree is represented as an adjacency list where each index represents a node and its corresponding value is a list of its child nodes.
Explanation: The maximum product is obtained from the subtree rooted at node 2 with values 11, 13, and 2, resulting in a product of 11*13*2 = 286, but considering all nodes, the product 7*11*13 = 1001 is the maximum.
Explanation: The maximum product is 2*3*4 = 24 from the subtree rooted at node 1.
Dynamic programming over tree structures
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak