2 children case not coming correctly

I followed the same approach. For the replace variable I used a function. I am not getting the correct input. Please help ASAP!

while deletion you have replace root node with node which is leftmost of right

NOT lefmost of rightmost

do some changes
first pass root->right
node* replacement = smallestMax(root->right)

and in smallestMax () remove first part
so finally

node* smallestMax(node* root) {
    while(root->left != NULL) {
        root = root->left;
    }
    return root;
}

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course

I made the above changes. But the output is still wrong. Please help

you have provide another code link
Please provide correct link of code

I’m really sorry @asaurabh_26. This is the correct link

hi @mohammadabdullahjawwad

correct condition for 1 child is
if(!(root->left&&root->right) ){

your condition
if(root->left||root->right){
will hold true even for 2 childeren
that’s why it is not working for 2 childeren case

Modified Code

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course

Such a silly mistake! Thanks man :slight_smile: