Given a Binary Tree and a Level. The task is to find the node with the maximum value at that given level.
The idea is to traverse the tree along depth recursively and return the nodes once the required level is reached and then return the maximum of left and right subtrees for each subsequent call. So that the last call will return the node with maximum value among all nodes at the given level.
Below is the step by step algorithm:
- Perform DFS traversal and every time decrease the value of level by 1 and keep traversing to the left and right subtrees recursively.
- When value of level becomes 0, it means we are on the given level, then return root->data.
- Find the maximum between the two values returned by left and right subtrees and return the maximum.
Below is the implementation of above approach:
- Find maximum level sum in Binary Tree
- Find maximum level product in Binary Tree
- Find the node with maximum value in a Binary Search Tree
- Get Level of a node in a Binary Tree
- Depth of the deepest odd level node in Binary Tree
- Level Order Successor of a node in Binary Tree
- Level Order Predecessor of a node in Binary Tree
- Get level of a node in binary tree | iterative approach
- Get maximum left node in binary tree
- Maximum difference between node and its ancestor in Binary Tree
- Find if given vertical level of binary tree is sorted or not
- Find mirror of a given node in Binary tree
- Find the Deepest Node in a Binary Tree
- Find n-th node in Preorder traversal of a Binary Tree
- Find distance from root to given node in 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 email@example.com. 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.