![]() |
VOOZH | about |
Given a binary tree, the task is to print all nodes between two given levels in a binary tree. Print the nodes level-wise, i.e., the nodes for any level should be printed from left to right.
Note: The levels are 1-indexed, i.e., root node is at level 1.
Example:
Input: Binary tree, l = 2, h = 3
Output:
2 3
4 5 6 7
The idea is to perform a preorder traversal of the binary tree while keeping track of the current level.
Step by step approach:
2 3 4 5 6 7
Refer to Print nodes between two given levels - Level Order for detailed explanation and approach.