sir please tell my approach is right or wrong
if right then what improvement in code
sir please tell my approach is right or wrong
if right then what improvement in code
Your logic is right but your implementation is wrong.
I think your code is not working for cases when either left subtree doesn’t exist or right subtree doesn’t exist.
I would suggest you to add edge cases separately.
Please see my implementation if you are unable to correct it.