It's not giving correct output

I have edited your code… The buildtree function that you were using was wrong… I have changed that as well… Kindly try to submit now…