Order of output not coming...please rectify the error

Hi Abdul,
There were a few issues with your code. First of all the input you are getting is not inorder. It is a simple array and you are supposed to construct the BST using it , in that order. Your sorting ruins the order and gives you a wrong tree. And therefore your build function was incorrect as well since the order is not sorted.
Secondly , for this particular problem you were supposed to choose the inorder predecessor as the replacement rather than the inorder successor . That is , the replacement for a node which is to be deleted and has two children will come from its left subtree rather than right.
I have made the said changes and marked them in the code and also shared my input function for you to refer. Please take a look and let me know if your doubt persists.
Updated Code - https://ide.codingblocks.com/s/98926

Remember that the Hackerblocks problem requires you to work for multiple testcases and not just one. Make sure to change that.

1 Like