Replace sum with greater nodes


Respected Sir/Mam
Actually my code is working and all test cases are also passing but my main doubt is about my approach. Am I using correct approach to solve it?
please help !

you have shared empty coe link but We can do it using a single traversal. The idea is to use following BST property. If we do reverse Inorder traversal of BST, we get all nodes in decreasing order. We do reverse Inorder traversal and keep track of the sum of all nodes visited so far, we add this sum to every node.

sir sorry about the link

here is the link of the code https://onecompiler.com/java/3wz8hv43b

sir, I have understood your approach but please check that whether i have used the correct approach or not??

yes, your approach is correct