VOOZH about

URL: https://www.geeksforgeeks.org/dsa/find-the-maximum-node-at-a-given-level-in-a-binary-tree/

⇱ Find the maximum node at a given level in a binary tree - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Find the maximum node at a given level in a binary tree

Last Updated : 11 Jul, 2025

Given a Binary Tree and a Level. The task is to find the node with the maximum value at that given level.

👁 Image

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: 

  1. Perform DFS traversal and every time decrease the value of level by 1 and keep traversing to the left and right subtrees recursively.
  2. When value of level becomes 0, it means we are on the given level, then return root->data.
  3. Find the maximum between the two values returned by left and right subtrees and return the maximum.

Below is the implementation of above approach: 


Output
49

Complexity Analysis:

  • Time Complexity : O(N), where N is the total number of nodes in the binary tree.
  • Auxiliary Space: O(N)

Iterative Approach:

It can also be done by using Queue, which uses level order traversal and it basically checks for the maximum node when the given level is equal to our count variable. (variable k).

Below is the implementation of the above approach:


Output
49

Complexity Analysis:

  • Time Complexity : O(N), where N is the total number of nodes in the binary tree.
  • Auxiliary Space: O(N) 
Comment
Article Tags: