Print k distance node from the target node

question–>
https://practice.geeksforgeeks.org/problems/nodes-at-given-distance-in-binary-tree/1
code–>


test cases are not passing help!!

Hey @sheikhhaji18

        if(dl!=-1){
            if((dl+1)==k){
                v.push_back(root->data);
                
            }
            else{
                printkdown(root->right,k-2-dl,v); //updated root->right
            }
            return dl+1;
        }
        int dr=printkfromtarget(root->right,target,k,v);
        if(dr!=-1){
            if((dr+1)==k){
                v.push_back(root->data);
                
            }
            else{
                printkdown(root->left,k-2-dr,v); //updated root->left
            }
            return dr+1;
        }

thank @Kartikkhariwal1

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.