Given a Binary Tree having positive and negative nodes, the task is to find maximum product level in it.
Input : 4 / \ 2 -5 / \ /\ -1 3 -2 6 Output: 36 Explanation : Product of all nodes of 0'th level is 4 Product of all nodes of 1'th level is -10 Product of all nodes of 0'th level is 36 Hence maximum product is 6 Input : 1 / \ 2 3 / \ \ 4 5 8 / \ 6 7 Output : 160 Explanation : Product of all nodes of 0'th level is 1 Product of all nodes of 1'th level is 6 Product of all nodes of 0'th level is 160 Product of all nodes of 0'th level is 42 Hence maximum product is 160
Prerequisites: Maximum Width of a Binary Tree
Approach : The idea is to do level order traversal of tree. While doing traversal, process nodes of different level separately. For every level being processed, compute product of nodes in the level and keep track of maximum product.
Maximum level product is 160
Time Complexity : O(n)
Auxiliary Space : O(n)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find maximum level sum in Binary Tree
- Find Maximum Level Sum in Binary Tree using Recursion
- Find the maximum node at a given level in a binary tree
- Queries to find the maximum Xor value between X and the nodes of a given level of a perfect binary tree
- Maximum absolute difference between any two level sum in a Binary Tree
- Find the Level of a Binary Tree with Width K
- Find if given vertical level of binary tree is sorted or not
- Sum and Product of maximum and minimum element in Binary Tree
- Find the numbers present at Kth level of a Fibonacci Binary Tree
- Sum and Product of minimum and maximum element of Binary Search Tree
- Difference between sums of odd level and even level nodes of a Binary Tree
- Check if max sum level of Binary tree divides tree into two equal sum halves
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Find maximum vertical sum in binary tree
- Find the maximum GCD of the siblings of a Binary Tree
- Find maximum among all right nodes in Binary Tree
- Find maximum (or minimum) in Binary Tree
- Product of nodes at k-th level in a tree represented as string
- Find maximum GCD value from root to leaf in a Binary tree
- Find the maximum path sum between two leaves of a binary tree
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.