all elements at depth k

 void printAtLevel(TreeNode<int>* root, int k){

    if (root==NULL){

        return;

    }

    if (k==0){

        cout<<root->data<<endl;

        return;

    }

    for (int i=0;i<root->children.size();i++){

        printAtLevel(root->children[i],k-1);

    }

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings