K distance from root
Given a Binary Tree and a number K. Print all nodes that are at distance K from root (root is considered at distance 0 from itself). Nodes should be printed from left to right. If K is more that height of tree, nothing should be printed.
For the above tree: K=3 Output: 5, 11, 4 K=4 Output: No output
The above problem can be solved using level order traversal. For every level traversed, keep decrementing K.
A Queue, input binary tree, input K
Example with explanation