Repace with greater sum

The question mentions BST, but they are making an AVL tree out of the given data, are we also supposed to make an AVL tree, because otherwise my ans is correct, just the order is not matching

hello @Tushar-Goel-1587999611286693
no , no need to make any avl tree,
build a balanced bst and then apply ur logic .

image

by changing the order of the sample input to build a balanced BST, I am getting the perfect answer, but I am still not being able to pass the test cases, pls tell if in test cases they are assuming it to be AVL or not

no they are not assuming it avl,
they are considering the given tree as a balanced bst

the tree u are building is not balanced,

Thanks you for the help, got it