This post is completed by 1 user

  • 0
Add to List
Medium

80. Find Nodes at Distance X from Root in a Tree

Objective: - Given Binary Tree, Print all the nodes which are X distance from the root

Example :

Nodes at X distances from root

Approach:

  • Do the preorder traversal, and pass x as a parameter.
  • While going down, at each level, keep reducing the x by 1
  • When x = 0, this means you have reached the nodes that are at x distance from the root, Print them.
 

Output:

Output:
Nodes at 3 distance from root :
 6 7 9