Https://ide.codingblocks.com/s/229537


I am getting the wrong output.

Your tree construction part is wrong. You have assumed that the tree is complete whereas, it hasn’t been mentioned anywhere in the question.