Although the code won’t give the required output , I am stuck at the inorder method;
This inorder is traversed from right node first.
Once the tree is created it will have all nodes on the right side.Now the sum variable is not getting updated after passing each node.
Whereas if the tree has all elements on the left side , then it is updated.
Not returning expected result
initialize sum variable outside the function
because changes are not persist
also your tree build is wrong
see this