Print All Nodes Between Two Given Levels

Objective: Given a binary Tree and two levels, Print all the nodes between those.

Input: A Binary Tree and two levels.

Output: Print all the nodes between given levels.


Print All Nodes Between Two Given Levels

Print All Nodes Between Two Given Levels


  • The solution of this problem is very simple, Do level order traversal and in recursive calls first add the right child and then left child.
  • Take a global variable say, currLevel which will store the current level while doing Level Order traversal.
  • Print only nodes between given levels.

Read this solution “ Level Order Traversal, Print each level in separate line” and implement the above approach.

Complete Code:


Print all nodes between nodes 2 and 4
10 15
20 25 30 35
40 45

Top Companies Interview Questions..-


If you find anything incorrect or you feel that there is any better approach to solve the above problem, please write comment.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: